Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Collections (2016, retired 2019) Lists Creating lists


For so many of the excersises i've had to look up the answer now, and this is just one of them

This challenge is just meant as a refresher. Create a single new list variable named my_list. Put 3 numbers and 2 strings into it in whatever order you want. For the last member, though, add another list with 2 items in it.

my_list = [1,2,3,"Apple","Pear"]

1 Answer

28,521 Points

This particular challenge do tend to trip up a lot of students so you don't have to feel too bad about being stuck on it. The key to this challenge is understanding that a list can contain any item, including lists. So you can place a list inside a list.

The challenge wants the last item to be a list which contains two items, like this:

my_list = [1,2,3,"Apple","Pear", ["Nested string 1", "Nested string 2"]]

In the above code I have added the following list ["Nested string 1", "Nested string 2"] as a single item in my_list. This is something which often looks odd to people starting programming, but is entirely valid. And is not actually that uncommon to find in real programs.

Thanks for the help on this particular problem, but my main problem is that I keep having to look up most of these answers, IM STUCK ugh