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

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

please help um stuck for almost 2 hours

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
b = musical_groups [0]
a = musical_groups [1]
n = musical_groups [2]
d = musical_groups [3]
i = musical_groups [4]
t = musical_groups [5]
s = musical_groups [6]

bands = b + a + n + d + i + t + s


for g in musical_groups:
  g = ", ".join(bands)
if len(bands)  :
    del bands

print (g)

8 Answers

Hi there, not sure if read the questions properly - for the first question you were very close.

# answer Challenge 1
for group in musical_groups: # loop through the list of lists
        print('. '.join(group) + "\n") # print each member joined by a seperator

# answer Challenge 2
for group in musical_groups: # loop through the list of lists
        if len(group) == 3: #only print out the groups with 3 members
            print('. '.join(group) + "\n") # print each member joined by a seperator

Hopefully this makes sense

Anthony Giordano
Anthony Giordano
1,783 Points
for group in musical_groups:
    print(", ".join(group))
    break
for tri in musical_groups:
    if len(tri) == 3:
        print(", ".join(tri))
Mercedes Aker
Mercedes Aker
6,544 Points

Thank you so much! worked!

# Try adding a break in between
for items in musical_groups:
    print(", ".join(items))
    break

for group in musical_groups:
    if len(group) == 3:
        print(", ".join(group))
Sneha Nagpaul
Sneha Nagpaul
10,124 Points

For when you get into list comprehensions:

[" ".join(group) for group in musical_groups if len(group) == 3]

Thank you

Mercedes Aker
Mercedes Aker
6,544 Points

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)) if len(group) == 3: print('. '.join(group))

Not sure what I'm missing. Anyone know?

Anthony Giordano
Anthony Giordano
1,783 Points

try adding a break in between. Worked for me.

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

That's the code I'm using in the second challenge. It prints out the trios but it won't pass the tests. Anyone knows why?

Mike Siwik
seal-mask
.a{fill-rule:evenodd;}techdegree
Mike Siwik
Full Stack JavaScript Techdegree Student 8,483 Points
for group in musical_groups:
    group = ", ".join(group)
    print(group)

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

the first code passes the first challenge. change the first code into the one below to pass the second challenge.