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

How do you only print out the trios for this challenge?

I find it confusing

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"],
]
# Your code here
for group in musical_groups:
    print(", ".join(group))

I understand that but i wanted to know how do you use that function and print out the trios only.

This is my code am i doing good so far: or group in musical_groups: print(", ".join(group)) if: len(group) = 3

I know its not right but i am just asking is the form right: for group in musical_groups: if = 3: print(", ".join(group))

Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

if = 3: is missing the conditional expression before the comparison, and should use ==

4 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

Hey Harjan Anand, you can find the length (number of members) using the len() function. Using len(group) returns an integer value.

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

Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

An if statement can be used of the form:

if <condition>:
    print(...)

where <condition> might be len(group) == 3

for group in musical_groups:
    if len(group) == 3:
        print(group)

what am i doing wrong?

Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

The join function needs to be reused from Task 1. As it is now, the group is printing as a list.

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

print(join.(group))

in this gesture? i tried this and another. Also thank you so much for being attentive to answering!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

Use the same print statement as Task 1. See OP code, above, for example. “, “.join(group)

again thank you so much for your fast replies and Im so sorry for some reason i cant still figure it out, i tried this originally but it kept giving me this error code and so i thought indenting again or spaces would fix it but it shows same error but the names jump around the error code given to me

AssertionError: 'John Lennon, Paul McCartney, Ringo Starr, George Harrison' unexpectedly found in 'Ad Rock, MCA, Mike D.\nJohn Lennon, Paul McCartney, Ringo Starr, George Harrison\nSalt, Peppa, Spinderella\nRivers Cuomo, Patrick Wilson, Brian Bell, Scott Shriner\nChuck D., Flavor Flav, Professor Griff, Khari Winn, DJ Lord\nAxl Rose, Slash, Duff McKagan, Steven Adler\nRun, DMC, Jam Master Jay\nAd Rock, MCA, Mike D.\nSalt, Peppa, Spinderella\nRun, DMC, Jam Master Jay' : Uh oh, I found a non-trio!

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

[MOD: added ```python formatting -cf]

for group in musical_groups:

if len(group) == 3:


    print(", ".join(group))
Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

The assertion error is stating it found a 4-member group in the output. Be sure the if statement is checking for 3 members, that is, a len of 3.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,454 Points

The reformatted code in the first comment on this answer passes the challenge! Yay!