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

Please help? I don't know if this solution is wrong or what?

I'm supposed to create list of members separated by comma and space and even though i checked this solution in my IDE the challenge won't accept it.

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
for i in range(len(musical_groups)):
    for j in range(len(musical_groups[i])):
        print(musical_groups[i][j], end=', ')
    print() 
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 herfor i in range(len(musical_groups)):

for group in musical_groups:
    group = ", ".join(group)
    print(group)

Your over thinking it.

1 Answer

To add to what Christopher said, keep in mind that you don't always need to do things in python the same way you might in a different language.

In many languages, if you want to go through a list, you need to use an index. But in python it is usually better to just go through the list directly. That is, instead of doing something like:

for i in range(len(musical_groups)):

you can go through the list directly like so:

for group in musical_groups:

This is a more obvious and direct way to handle it. Python gives you a very easy way to go through lists.

Likewise using join is a very easy way to insert the commas between each member of the group.

As to why the system rejects your answer, I think it specifically wants you to use the join method. Also, you are printing a comma at the very end of the line, where you only need commas between each member, not after the last member.

Thank you very much. I just forgot the .join() method and somehow couldn't find it, but now i'll certainly remember it.