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

Python Introducing Lists Build an Application Multidimensional Musical Groups

I am stuck.

I need help with this code

groups.py
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
MOD
Chris Freeman
Treehouse Moderator 68,428 Points

Hey 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!!

This 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

for 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
Chris Freeman
Treehouse Moderator 68,428 Points

In 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 over musical_groups not groups.

I dont know why it says : SyntaxError: invalid character in identifier This is my 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
for group in musical_groups:
    print(, .join(group))
Chris Freeman
Chris Freeman
Treehouse Moderator 68,428 Points

The 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.