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 Python Collections (2016, retired 2019) Lists Creating lists

Need help clarifying what challenge is asking.

I'm having trouble comprehending what this challenge is asking?

lists.py
my_list = [1, 2, 3, 'abc', 'bde']
second_list = my_list + [4, 5]


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.

1 Answer

cpauciello
cpauciello
26,629 Points

You almost got it.

You're being asked to create a list variable, and put 3 numbers and 2 strings inside of it. Which you've done.

# Create a list variable called my_list
# Add 3 numbers and two strings into it

my_list = [ 1, 2, 3, 'abc', 'bde' ]

Now I assume it's the 'For the last member' part that's tripped you up? You need to place a second list as the last item of your list variable.

So, add some square ([ ]) brackets as the last item of your list variable, then add 2 items inside this new second (nested) list.

# Add a second list 'For the last member'
# 'last member' meaning the last item of your list variable.
# my_list = [ 1, 2, 3, 'abc', 'bde', [ ] ]
my_list = [ 1, 2, 3, 'abc', 'bde', [4, 5] ]

You can also do this using pythons 'append' method:

# Create a list variable named 'my_list'
# Place 3 numbers and two strings into it
my_list = [ 1, 2, 3, 'abc', 'bde' ]

#For the last object in the list
# create a second list and add it to the end of your list variables list using 'append':
my_list.append([ 4, 5 ])

Either way you decide to do it, printing your list to the screen should look something like this:

print( my_list )

 [ 1, 2, 3, 'abc', 'bde', [4, 5] ]                                                                              

Hope that helps!

That did the trick, thanks!