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 trialAditya Mehra
5,970 PointsI 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
Treehouse Moderator 68,441 PointsYuck! 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
.
Kenneth Love
Treehouse Guest TeacherYep, that's me putting in "first" when I meant "last". Question has been updated. Thanks both of you!
Chris Freeman
Treehouse Moderator 68,441 PointsMUCH less horrible now, in fact it now makes perfect sense! Thanks for the update!
Aditya Mehra
5,970 PointsAditya Mehra
5,970 PointsGot you.....Thanks Chris.
Jan M
1,053 PointsJan M
1,053 PointsHey Chris, wouldnt the .extend() funtion also allow us to plac the 1 at the end of the list?
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest TeacherJan M
.extend()
requires an iterable and ints aren't iterable, so, no, it'll cause aTypeError
instead.