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 trialmerrill sequeira
2,874 Pointsdon't understand the question. can some one help?
shouldn't the code
for group in musical_groups: print(group)
be enough ? - dont understand the question
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"],
]
all_mems=[]
for group in musical_groups:
all_mems.append(group)
print (str(all_mems))
2 Answers
Jimmy Sweeney
5,649 PointsIs this for part 1 of the challenge? The challenge is asking you to print out a set of strings. Each string should be the members of a musical group separated by commas.
Right now your code simply prints out the original list as a string. So the following would do the exact same thing as your code.
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"],
]
print(str(musical_groups))
Notice that original list is a list of lists. So each iteration in the for-loop will give you a list. For instance, the first iteration through musical_groups is ["Ad Rock, "MCA", "Miked D."]. You will want to use the join() method in order to join the strings within that first iteration into a new string. And then do that for each iteration.
Hope that helps!
Jimmy Sweeney
5,649 PointsThat should do it. But you may want to add spaces after the commas. :)
merrill sequeira
2,874 Pointsthanks
merrill sequeira
2,874 Pointsmerrill sequeira
2,874 Pointsok, so like ---
for grp in musical_groups: print(",".join(grp))
??