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 trialChris Drummond
1,315 PointsMultidimensional Lists - AssertionError: Task Number 2: Print only groups with 3 band members
I have looked at other questions and tried their responses but I cannot seem to get this code to work.
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 band in musical_groups:
seperator = ", "
bands = seperator.join(band)
print(bands)
for group_members in musical_groups:
if (len( group_members) == 3):
print(", " .join(group_members))
1 Answer
Mel Rumsey
Treehouse ModeratorHey Chris Drummond, you are close here, but we really only need to add one line of code to your previous statement:
for band in musical_groups:
# <--- Add an *if* statement here checking if the length of band is equal to 3: then do this v v v
seperator = ", "
bands = seperator.join(band)
print(bands)
We only want to print bands that have 3 people, so changing your previous code to operate only if there are 3 people will pass in this case.
Hope this helps! Happy coding :D
Chris Drummond
1,315 PointsChris Drummond
1,315 PointsMel Rumsey Got, thanks for the help