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 trialHarjan Anand
780 PointsHow do you only print out the trios for this challenge?
I find it confusing
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))
Harjan Anand
780 PointsThis is my code am i doing good so far: or group in musical_groups: print(", ".join(group)) if: len(group) = 3
Harjan Anand
780 PointsI know its not right but i am just asking is the form right: for group in musical_groups: if = 3: print(", ".join(group))
Chris Freeman
Treehouse Moderator 68,441 Pointsif = 3:
is missing the conditional expression before the comparison, and should use ==
4 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsHey Harjan Anand, you can find the length (number of members) using the len() function. Using len(group)
returns an integer value.
Post back if you need more help. Good luck!!!
Chris Freeman
Treehouse Moderator 68,441 PointsAn if statement can be used of the form:
if <condition>:
print(...)
where <condition>
might be len(group) == 3
Chris Freeman
Treehouse Moderator 68,441 PointsThe form should be:
for ...
if ...
print(....
Evelyn Meza
4,226 Pointsfor group in musical_groups:
if len(group) == 3:
print(group)
what am i doing wrong?
Chris Freeman
Treehouse Moderator 68,441 PointsThe join
function needs to be reused from Task 1. As it is now, the group is printing as a list.
Post back if you need more help. Good luck!!!
Evelyn Meza
4,226 Pointsprint(join.(group))
in this gesture? i tried this and another. Also thank you so much for being attentive to answering!
Chris Freeman
Treehouse Moderator 68,441 PointsUse the same print statement as Task 1. See OP code, above, for example. “, “.join(group)
Evelyn Meza
4,226 Pointsagain thank you so much for your fast replies and Im so sorry for some reason i cant still figure it out, i tried this originally but it kept giving me this error code and so i thought indenting again or spaces would fix it but it shows same error but the names jump around the error code given to me
AssertionError: 'John Lennon, Paul McCartney, Ringo Starr, George Harrison' unexpectedly found in 'Ad Rock, MCA, Mike D.\nJohn Lennon, Paul McCartney, Ringo Starr, George Harrison\nSalt, Peppa, Spinderella\nRivers Cuomo, Patrick Wilson, Brian Bell, Scott Shriner\nChuck D., Flavor Flav, Professor Griff, Khari Winn, DJ Lord\nAxl Rose, Slash, Duff McKagan, Steven Adler\nRun, DMC, Jam Master Jay\nAd Rock, MCA, Mike D.\nSalt, Peppa, Spinderella\nRun, DMC, Jam Master Jay' : Uh oh, I found a non-trio!
Evelyn Meza
4,226 Pointsfor group in musical_groups:
if len(group) == 3:
print(", ".join(group))
[MOD: added ```python formatting -cf]
Evelyn Meza
4,226 Pointsfor group in musical_groups:
if len(group) == 3:
print(", ".join(group))
Chris Freeman
Treehouse Moderator 68,441 PointsThe assertion error is stating it found a 4-member group in the output. Be sure the if
statement is checking for 3 members, that is, a len
of 3.
Chris Freeman
Treehouse Moderator 68,441 PointsThe reformatted code in the first comment on this answer passes the challenge! Yay!
Harjan Anand
780 PointsHarjan Anand
780 PointsI understand that but i wanted to know how do you use that function and print out the trios only.