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 trialLuis Martinez
5,986 Pointswhy is my code printing everything if Im excluding groups with more than 3 objects in them??
i even made a copy of the multi-dimentional list and so far nothing seems to work. What am I missing?
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"],
]
s = ", "
# Your code here
for groups in musical_groups:
print(s.join(groups))
groups = groups.copy()
if len(groups) == 2:
print(groups)
3 Answers
akoniti
1,410 PointsHi Luis,
The first thing I see is that your for loop is actually printing the groups before checking the length with this early line:
print(s.join(groups))
Second, your length check isn't actually finding any results, because all of these lists contain 3 or more values.
So, if you modified your code as follows, it will just print groups with 3 or less values:
for groups in musical_groups:
#print(s.join(groups))
#groups = groups.copy()
if len(groups) < 4:
#print(groups)
print(s.join(groups))
I left your original lines in, commented out, so you could more easily follow the changes I made. Good luck!
KRIS NIKOLAISEN
54,972 PointsI'm kind of confused as to what you are asking. Everything prints from this line:
print(s.join(groups))
then you have a condition checking for a length of 2. Since none of the groups match this nothing further prints. If you change the 2 to 3 you will print all the groups with three members in addition to the above.
Luis Martinez
5,986 Pointsthanks to both of you for your time! You guys are awesome!
Luis Martinez
5,986 PointsLuis Martinez
5,986 Pointsoh that's so true! I didn't even realize it!