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

In a multi dimensional list, how do I loop through each list and separate the objects with a comma?

I'm not certain that this is the right phrasing... it's the exercise at the very end of the beginning lists course taught by Craig Dennis. Thanks a lot!

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 musical_group in musical_groups
    print("{}".format(musical_groups))
musical_group.join(", ")

2 Answers

Steven Parker
Steven Parker
231,275 Points

You have the right idea to use "join", but:

  • the "for" line should end with a colon
  • the join syntax is "backwards", call the method on the string and pass the list as the argument
  • the joined list will be the thing you want to "print" in the loop

no matter what I try it keeps saying there are two problems with my code. I just don't understand what i'm doing wrong, and how every single time i'm two steps away from being correct :((

Steven Parker
Steven Parker
231,275 Points

What I was suggesting was fixing the syntax issues and then putting the "join" expression in the "print":

for musical_group in musical_groups:
    print(", ".join(musical_group))

This comes up as incorrect and says that there are two problems with my code. When i rearrange it from this position into something that I think would work it usuallyyy says that there are two problems with my code, unless it says it's just invalid syntax.

variable = ", ".join(musical_groups) for musical_group in musical_groups: print({} , variable.format(musical_groups))

thank you for your help!