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 trialTatenda Marshall Manuel
8,055 PointsAwesome! 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
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
Stuart McIntosh
Python Web Development Techdegree Graduate 22,874 PointsHi 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
1,783 Pointsfor group in musical_groups:
print(", ".join(group))
break
for tri in musical_groups:
if len(tri) == 3:
print(", ".join(tri))
Mercedes Aker
6,544 PointsThank you so much! worked!
wizard xxdx
Python Development Techdegree Student 1,096 Points# 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
10,124 PointsFor when you get into list comprehensions:
[" ".join(group) for group in musical_groups if len(group) == 3]
Tatenda Marshall Manuel
8,055 PointsThank you
Mercedes Aker
6,544 Pointsmusical_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
1,783 Pointstry adding a break in between. Worked for me.
Lukasz Wolk-Laniewski
1,622 Pointsfor 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
Full Stack JavaScript Techdegree Student 8,483 Pointsfor 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.