Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

How to remove the first Item from a list?

I have the rundown [0, 1, 2, 3, 4] I'd prefer to make it into [1, 2, 3, 4]. How would I approach this?
by

3 Answers

akshay1995
Slicing:

x = [0,1,2,3,4]
x = x[1:]

Which would actually return a subset of the original but not modify it.
sandhya6gczb
You can use
the list.pop(index)

>>> l = ['a', 'b', 'c', 'd']
>>> l.pop(0)
'a'
>>> l
['b', 'c', 'd']
>>>

Also, you can use
del list(index)


>>> l = ['a', 'b', 'c', 'd']
>>> del l[0]
>>> l
['b', 'c', 'd']
>>>
RoliMishra
With list slicing, see the Python tutorial about lists for more details:

>>> l = [0, 1, 2, 3, 4]
>>> l[1:]
[1, 2, 3, 4]

Login / Signup to Answer the Question.