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

Andreas M
Andreas M
1,311 Points

How to merge a multi-dimensional group into a string?

I am working on the code-challenge for multi-dimensional groups. Below you will see my code. The output basically creates a print-out of the members, but it prints each member like 50 times! What am I doing wrong?


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

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

print(member)

1 Answer

Josh Keenan
Josh Keenan
20,315 Points

I am not entirely sure as the formatting is gone, but I will post my solution and explain it.

for group in musical_groups:
    print((', ').join(group))

This is a short and simple way of doing this, joining each group with the string required and printing it, all at once.

I think you have the right idea but you don't need to take as many steps to get there, if that makes sense. Hope this helps, and feel free to ask any questions.