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

I'm not sure how to print only the groups with 3 members.

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 item in musical_groups:
    if len(musical_groups) == 3:
        print(", ".join(item))

2 Answers

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree seal-36
Rohald van Merode
Treehouse Staff

Hey fionaj 👋

You're super close to the solution here! There's only one thing that stops your code from working and that is the conditional that you've created.

Currently, you're checking the length of the musical_groups list which is 7 (all nested lists in musical_groups) Instead you'll want to check the length of the item which represents a single group in your loop 🙂

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

Hope this helps!

Robbie Baker
Robbie Baker
3,697 Points

The key here is just to remember items as objects inside the list. These can be other lists, strings, ints, etc.