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 (Retired) Lists Redux List creation/extension methods

Aditya Mehra
Aditya Mehra
5,970 Points

I want my_list to have 1 as the first item. Complete this method call: my_list._______(1) What is the method?

Which method is used?

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

Yuck! The quiz is asking a horrible question. The answer expected by the quiz is append.

This is horrible since this answer only apples when my_list is an empty list: []

If my_list were empty, I would not need a method to add the value, I could simply assign it:

    my_list = [1]

The answer when my_list is not empty then answer would be:

    my_list.insert(0, 1) #<-- insert, at index 0, the value 1

UPDATE: Kenneth has updated the question to read "I want my_list to have 1 as the last item. Complete this method call: my_list._______(1) What is the method?". This makes SO much more sense now. Expected answer remains append.

Aditya Mehra
Aditya Mehra
5,970 Points

Got you.....Thanks Chris.

Hey Chris, wouldnt the .extend() funtion also allow us to plac the 1 at the end of the list?

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Jan M .extend() requires an iterable and ints aren't iterable, so, no, it'll cause a TypeError instead.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Yep, that's me putting in "first" when I meant "last". Question has been updated. Thanks both of you!

Chris Freeman
Chris Freeman
Treehouse Moderator 68,426 Points

MUCH less horrible now, in fact it now makes perfect sense! Thanks for the update!