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 trialOliver Hoad
23,622 PointsHow am I supposed to only select the lists with three people?
I'm not sure how I am supposed to select the correct lists to print with the join method.
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))
1 Answer
Steven Parker
231,269 PointsAnd easy way to get a count of members in a list is by using the "len()
" function. Combining that with a comparison in an "if" statement should do the job nicely.
Matthew Earlywine
3,508 PointsI've been trying to figure this one out but I am struggling. Can I get a little push? for group in musical_groups: print(", ".join(group))
if group in musical_groups:
print(group.len(musical_groups))
Steven Parker
231,269 PointsIf you're working on the first task you can take a peek at Oliver's solution at the top of this page.
Then for task 2, you can add an "if" statement to control when the print statement runs. It can test the list to see if it has exactly 3 elements.
Matthew Earlywine
3,508 PointsI am working on task 2. I tried to use the if statement with len but I am not sure if I am understanding the organization with using it. I used the = 3 for the len and I get a traceback.
for group in musical_groups: if len(group) = 3 print(", ".join(group)
Oliver Hoad
23,622 PointsI have tried it out with an "if" statement but I have not done it correctly. Which one of the videos covers this?
for group in musical_groups:
print(", ".join(group))
if len(group) == 3:
print(", ".join(group))
Craig Dennis
Treehouse TeacherI see the problem...only print in the if block. You are printing twice if they have 3.
Super close!
Oliver Hoad
23,622 PointsOliver Hoad
23,622 PointsThanks for the help! I found the answer here: https://teamtreehouse.com/community/im-not-sure-what-i-did-wrong
I feel bad that I wasn't able to figure it out without looking at someone else's answer though, but now that I look at it, it makes more sense. I also didn't understand how the ".len()" function was supposed to be used. is it like "len(group)" or "group.len()" ??? Thanks for responding so quickly!