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 trial

Python Introducing Lists Build an Application Multidimensional Musical Groups

I don't know how to figure this out.

I started off with a loop

for group in musical_groups: print(group)

But i don't know where to go from here. I need to join these somehow.

groups.py
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"],
]

1 Answer

Louise St. Germain
Louise St. Germain
19,424 Points

Hello Yusuf,

Yes, your instinct is correct, you do need to join these! So your next step would be to look up the join function, which you've already seen in an earlier course video. The format for that is:

"string_that_goes_in_between_the_items".join(list_of_items_to_be_joined)

I think you can figure it out from here, since you already set up an iteration through each group in the list of groups. Each group is a list (of people). The items (people) in each group list are what you want to join together. The challenge already tells you that you should have ", " between the items, so you just need to plug everything into the template above.

Generally speaking, if it's a struggle to figure out what the code needs to be for a particular problem, there are a few tips that might help you figure out the problem.

  • Try writing out the code in words first - this is known as pseudo-code. For example, the pseudo-code for the problem above might look like:
For each band in list of bands:
    Join them together with ", " in between each person in the band.
    Print the string above.
    ^^ (These two can be done in one line of code but I separated them out to make it simpler.)

This is a pretty simplistic example, but for more complex programs, it can be a life saver. If you can't describe in regular words what you're trying to do, you won't really know what you need to do with your code either.

  • If you know what you need to do but forget the syntax in the programming language (this happens to everyone), try looking up the syntax online. This could be in the official documentation for Python, or you could just google something like "Python join function", and all kinds of tutorials pop up - these can be really helpful.

  • Along those same lines, try taking notes by hand as you go through the Treehouse videos, if you aren't already. (I know, this is super old-school! :-)) You will have an easy-to-find record of what you just learned, and the process of physically writing it out is a much more active way of learning and retaining than just watching a video. I know I've referred to my notes a LOT and it's been really helpful.

Anyway, I hope this helps. Good luck with solving this challenge, and the next ones!

Thanks for the great answer. I didn't think about pseudo-code that's very useful.