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!

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 to show lists with only 3 member in multi dimensional list

How do I print only the lists with 3 members in the 2 dimensional list

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

1 Answer

Hi Elroy,

A few things I’ll quickly point out before we solve this challenge that will be helpful to you on your coding journey.

First, the break keyword immediately exits a loop. It doesn’t just exit that iteration of the loop, it exits it period.

Meanwhile, the continue keyword skips everything in the loop after continue and immediately begins the next iteration of the loop.

Right now there’s no code written after continue so it’s not actively doing anything.

Third, you’re testing the len() of group when you should be testing the len() of groups (with an s at the end). group is undefined.

What I’ve typically seen is students writing an if statement, if len(groups) == 3:, then nesting the print statement within it.

But your code has prompted a new idea.

You could write:

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

The code above says, if the length of the groups is not 3 then skip the print statement and begin the next iteration at the top.

Hope that helps. Keep it up, coder!

Laura Mora Freeman
Laura Mora Freeman
8,192 Points

Thank you, very useful to clarify the challenge.