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 trialvincent juma
1,159 PointsHello everyone, I'd really appreciate some help on grouping the below items in trios in my code
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? It should still use the joined string format from task 1
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"],
]
new_list = []
for item in musical_groups:
new_list += item
final_string = ", ".join(new_list)
print(final_string)
1 Answer
Daniel Turato
Java Web Development Techdegree Graduate 30,124 PointsAs you are already looping through each group, its as simple as checking the length of each group to see how many members are in each of them. So your code would look like this:
for group in musical_groups:
if len(group) == 3:
print(", ".join(group))
vincent juma
1,159 Pointsvincent juma
1,159 PointsThanks so much