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

How to use .insert

What should I have done?

lists.py
best = [1, 2, 3] 
best.extend([4, 5])
best.insert([0, "start"])

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Nick,

You are so close. :smile:

When you did the second task and appended two new values, the values went inside square brackets that are inside parenthesis. This is because you had to pass two arguments, but the append() method only take one parameter. Using the square brackets created a tuple, and thus it was only a single parameter being passed in.

Now the third task, using the insert() method, you need to pass in two parameters. One for the position and one for the value. When you enclose these inside of square brackets, you are creating a tuple, so the method is missing a value. The compiler sees best.insert([0, "start"]) as being told to insert the number 0 and the string "start", and therefore doesn't have a place to insert them.
All you need to do is remove the square brackets, and then you'll have 2 arguments being passed in, and the compiler then reads it as insert the string at position 0.

I hope that makes sense. :)

Keep Coding! :dizzy: