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!
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 trial
Efe Mirkan Guner2,413 Points
can you help me for this code please
i can not complete it
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"], ] list_number=1 for list in musical_groups: print(list) list_number+=1 abc= ", ".join(list)
You're overcomplicating stuff. Since
musical_groups is a two-dimension object, get hold of each list in the second dimension by creating a
for loop targeting the second dimension and printing each item of each list.
Taking your solution into account;
list_number=1 👈# Why? for list in musical_groups:👈#Here you're targeting the first dimension not the second. Since musical_groups is a list of #lists specify the inner dimension of the musical_groups which is musical_groups here 0 #is the first list within musical_groups. print(list) list_number+=1 abc= ", ".join(list)
So let me give you a template:
for x in musical_groups: 👈#Since there are 7 lists within musical_groups' list, use index to target all of them. print(", ".join(x))