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 trialJordan Winka
3,884 PointsCouldn't we just do a join and then print the string?
Wouldn't this work too?
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
members = ", ".join(musical_groups)
print (members)
2 Answers
Steven Parker
231,248 PointsThat code is attempting to join all the groups into a single string, but the "join" method doesn't know how to handle a list containing other lists.
The challenge wants you to join the members of each individual group and print those out one at a time. That's where the loop comes in handy.
Now just as a preview, there is a way to do this with a one-liner using something called "list comprehension" which you will get to in later courses:
members = "\n".join([", ".join(g) for g in musical_groups])
print(members)
But this won't solve the challenge because it's specifically wanting you to use a loop.
jhon white
20,006 Points#first challenge :
for group in musical_groups:
print(", ".join(group))
#second challenge:
for group in musical_groups:
if len(group) == 3 :
print(", ".join(group))
Good luck :))