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 trialBrent Capuano
949 PointsNeed help on this quiz
Here is a multi-dimensional list of musical groups. The first dimension is group, the second is group members.
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"],
]
line_number = 1
members = ", ".join(musical_group)
for group in musical_groups:
print("Group #{}:" + members.format(line_number))
line_number += 1
1 Answer
รyvind Andreassen
16,840 PointsHey Brent Capuano,
I think you need to re-read the task. But you are actually pretty close, but let's break it down.
line_number = 1
members = ", ".join(musical_group)
for group in musical_groups:
print("Group #{}:" + members.format(line_number))
line_number += 1
It doesn't care about the position the band has in the list so you can get rid of the line_number
. You are also declaring members
by joining musical_group
, the problem is that this variable doesn't exist. But the solution is on that line.
If we move declaring members to inside the for-loop, and print members
you'll pass the challenge.
for group in musical_groups:
members = ", ".join(group)
print(members)
To make this code even more concise you could also just print the join function.