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 trialjames Pradhan
Courses Plus Student 1,159 PointsNots sure with this one
grocery_list = ["milk", "eggs", "bread", "ice cream", "carrots", "potatoes"] last_item = grocery_list.pop first_item = last_item.shift[0]
grocery_list = ["milk", "eggs", "bread", "ice cream", "carrots", "potatoes"]
last_item = grocery_list.pop
first_item = last_item.shift[0]
1 Answer
Alexander Davison
65,469 PointsYou are close! Just keep in min that shift
is very similar to pop
. The only thing shift
does differently is that it removes the first item instead of the last item. It returns the first item as well, like the pop
method does.
So this means you should call the method on the grocery_list
array, not the first_item
string. Also, you shouldn't pass in an argument to the shift
method; remember shift
already knows by default to remove the first element and isn't expecting an index.
I hope this helps
~Alex
james Pradhan
Courses Plus Student 1,159 Pointsjames Pradhan
Courses Plus Student 1,159 PointsOMG1 Thanks a lot for your time and help. have a great day.
Alexander Davison
65,469 PointsAlexander Davison
65,469 PointsNo problem :)
Can you please provide a best answer as well? Thank you! ~Alex