Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Harjan Anand](https://secure.gravatar.com/avatar/9dff410b4174fc18623c42dd5a3a163c?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Harjan Anand
780 PointsI am stuck.
I need help with this code
musical_groups = [
["Ad Rock", "MCA", "Mike D."],
["John Lennon", "Paul McCartney", "Ringo Starr", "George Harrison"],
["Salt", "Peppa", "Spinderella"],
["Rivers Cuomo", "Patrick Wilson", "Brian Bell", "Scott Shriner"],
["Chuck D.", "Flavor Flav", "Professor Griff", "Khari Winn", "DJ Lord"],
["Axl Rose", "Slash", "Duff McKagan", "Steven Adler"],
["Run", "DMC", "Jam Master Jay"],
]
# Your code here
musical_groups = input(", ")
1 Answer
![Chris Freeman](https://uploads.teamtreehouse.com/production/profile-photos/1153532/micro_image.jpg)
Chris Freeman
Treehouse Moderator 68,425 PointsHey Harjan Anand, let's see if we can walk through the challenge.
Here is a multi-dimensional list of musical groups. The first dimension is group, the second is group members.
The first dimension is the group. This means it could have been written as:
group1 = ["Ad Rock", "MCA", "Mike D."],
group2 = ["John Lennon", "Paul McCartney", "Ringo Starr", "George Harrison"],
group3 = ["Salt", "Peppa", "Spinderella"],
group 4 = ["Rivers Cuomo", "Patrick Wilson", "Brian Bell", "Scott Shriner"],
group 5 = ["Chuck D.", "Flavor Flav", "Professor Griff", "Khari Winn", "DJ Lord"],
group 6 = ["Axl Rose", "Slash", "Duff McKagan", "Steven Adler"],
group 7 = ["Run", "DMC", "Jam Master Jay"],
musical_groups = [group1, group2, group3, group4, group5, group6, group7]
Can you loop through each group and output the members joined together with a ", " comma space as a separator, please?
This by be better phrased as "can you loop through all the groups in musical_groups
and print out each group members into a string using a comma and space as a separator."
Now you can see that a for
loop over musical_groups
and a print
statement for each loop group would work nicely. In the form like:
for group in groups:
print(", ".join(group))
The above isn’t the exact answer but should get you extremely close.
Post back if you need more help. Good luck!!
Harjan Anand
780 PointsHarjan Anand
780 PointsThis is my code so far but i need help on what to do next:
musical_groups = [ ["Ad Rock", "MCA", "Mike D."], ["John Lennon", "Paul McCartney", "Ringo Starr", "George Harrison"], ["Salt", "Peppa", "Spinderella"], ["Rivers Cuomo", "Patrick Wilson", "Brian Bell", "Scott Shriner"], ["Chuck D.", "Flavor Flav", "Professor Griff", "Khari Winn", "DJ Lord"], ["Axl Rose", "Slash", "Duff McKagan", "Steven Adler"], ["Run", "DMC", "Jam Master Jay"], ] musical_groups = {}: for musical_groups in
Chris Freeman
Treehouse Moderator 68,425 PointsChris Freeman
Treehouse Moderator 68,425 PointsI’ve updated my answer above.
Harjan Anand
780 PointsHarjan Anand
780 Pointsfor group in groups: print(“, “.join(group)) print()
this is my code and i know i am extremly close but i have no idea what to do next and when you tell i think i will understand.
Chris Freeman
Treehouse Moderator 68,425 PointsChris Freeman
Treehouse Moderator 68,425 PointsIn should be
group in musical_groups
. I had given the form of the answer to see if you could grasp that the loop should iterate overmusical_groups
not groups.Harjan Anand
780 PointsHarjan Anand
780 PointsI dont know why it says : SyntaxError: invalid character in identifier This is my code:
Chris Freeman
Treehouse Moderator 68,425 PointsChris Freeman
Treehouse Moderator 68,425 PointsThe code parser doesn’t like the stylized quotation marks. It sees it as
print(“, “.join(group))
due to the non-ASCII or non UTF-8 characters for quotes.This is referred to as “Mojibake”, garbled text that is the result of text being decoded using an unintended character encoding. The result is a systematic replacement of symbols with completely unrelated ones, often from a different writing system.