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 trialAlana Warson
5,296 Pointshere is a multi-dimensional list of musical groups. The first dimension is group, the second is group members.
This multidimensional lists was covered in the last portion of videos I watched. Why can't questions and challenged be in the same track of videos that we are currently going over, Therefore, I have no idea of trying to loop through via dimensions and output members. Can I please get help? Is there an easier track besides Python?
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
6 Answers
Peter Vann
36,427 PointsHi Alana!
Happy Easter (if you're into that sort of thing)!!! (I spent today visiting my Mom!?!)
This whole challenge is just exploring nested/2-dimensional lists (a list of lists).
Also, it helps to understand how the Python join works (which is essentially BACKWARDS from how you would code it in JavaScript).
More info:
https://www.w3schools.com/python/ref_string_join.asp
And then, of course a for/in loop would be a good looping structure.
This passes 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"],
]
# Your code here
for group in musical_groups:
print( ", ".join(group) ) # "group" being a list of members
But now you have to filter the groups and only print the ones with 3 members (Hint: You'll need to add an if statement).
Sidebar: I try to spend equal time on JS, Python, and PHP (and HTML and CSS) - they all have their place!
Lemmeeno if you can figure out task 2.
If not, I'll help you further.
I hope that helps.
Stay safe and happy coding!
Alana Warson
5,296 PointsAh, Happy Easter too! I celebrate some holidays but usually try to stay away from my dysfunctional family 😁 My first line of code was: for musical groups in musical groups. Thank you for your help again. Have a great day!
Alana Warson
5,296 PointsOK, I wrote the code you showed and I got an invalid syntax. I went back and copy/paste your code and I still got a syntax error.
Peter Vann
36,427 PointsHi Alana!
This passed task 1 for me:
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_members in musical_groups:
print( ", ".join(group_members) )
(I changed group to goup_members for clarity.)
At first, it didn't pass because somehow my first line became:
mmusical_groups = [
(Note the mistake: double mm)
(A copy-n-paste error, evidently...)
This passes task 2:
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_members in musical_groups:
if len(group_members) == 3: # filters-out all but the 3-member groups
print( ", ".join(group_members) )
I hope that helps.
Stay safe and happy coding!
Alana Warson
5,296 PointsOk the funny thing ... I cannot find the track this problem was at.
Alana
Peter Vann
36,427 PointsHi Alana!
Try here:
https://teamtreehouse.com/library/introducing-lists
I hope that helps.
Stay safe and happy coding!
Riley Ittidecharchoti
3,195 PointsThanks for this... I almost had it!