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

Now I'd like to see only groups that are trios, you know 3 members. So can you please only print out the trios?

Hey there, Having a bit of a struggle with this one. I thoroughly watched the videos and must have missed this concept. Can someone help me get it right and explain what's happening in the right code? Thanks!

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"],
]
for band in musical_groups:
    seperator = ", "
    bands = seperator.join(band)
    if len(bands) == 3:
        print(bands)

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You are very close!! If you join the band members into a string before the len() check, you are checking the length of the string, which is almost certainly not 3 characters.

Post back if you need more help. Good luck!!!

Hi Matthew!

Join syntax is a little backwards from how you would do it in, say, Javascript.

This passes task 1:

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:
    if len(band) == 3: # you want to test the length of each "band list", and only include the ones with 3 members
        print( ", ".join(band) )

More info:

https://www.w3schools.com/python/ref_string_join.asp

I hope that helps.

Stay safe and happy coding!