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 Combining Lists

Come on! This should be correct, right?

adding to a list

lists.py
best = ["cat", "dog", "bird"]
best.append("fish", "dino")

1 Answer

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

append takes exactly one argument so you're getting an error. the extend method would do what you are trying to do, but the argument needs to be a list, so add [] around the items. you can append a list to a list, but it will add only one element to the list, which will itself be a list, so you'll have a nested list. extend will "flatten" the added list resulting in a non-nested list with a length equal to the sum of the number of elements in the two lists.

Thank you so much for your comprehensive response James. I tried the .append method in my personal Python Terminal, and it seemed to work. But in Workspaces – not so much. I solved it though, with the:

best += ["fish", "dino"]

It seemed to do the trick!