Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get everything from the list except the first element using list slicing [duplicate]

People also ask

How do you exclude one element from a list in Python?

pop() In python list's pop() function will remove the element at given index and also returns the deleted element. If index is not given then it deletes the last element.

How do I extract the last 3 items from a list in Python?

Method #2 : Using islice() + reversed() The inbuilt functions can also be used to perform this particular task. The islice function can be used to get the sliced list and reversed function is used to get the elements from rear end.

How do you remove items from the front of a list in Python?

Del operator has similar working as pop() method to remove the elements from the lists in python. The del operator removes the element from the list at a specified index location but does not return the removed item, unlike the pop() method.

How do you get rid of the first item in a list?

The remove() method removes the first matching element (which is passed as an argument) from the list. The pop() method removes an element at a given index, and will also return the removed item. You can also use the del keyword in Python to remove an element or slice from a list.


You can just do [1:]. This will work on both versions.


It can be done like this:

list[1:]