Join Regular Classroom : Visit ClassroomTech

Python List – How to remove first row in a list

There are many ways of doing it-

pop method – list.pop()
remove method – list.remove(list[index])
del function – del list[index]

Here is an example for you

# Python code to understand how to remove first row in a list
# www.codewindow.in

b = [[10, 11, 12], [13, 85, 15], [18, 17, 77]]
c = [['a', 's'], ['d', 'f'], ['k', 'l']]
d = [["code", "window"], ["repeat", "code"]]

#using remove method
b.pop(0)
print(b)

#using del method
del c[0]
print(c)

#using remove method
d.remove(d[0])
print(d)

Output:

[[13, 85, 15], [18, 17, 77]]

[['d', 'f'], ['k', 'l']]

[['repeat', 'code']]

Explanation:
Here, pop(0) pops the first list from the list.
remove(b[0]) removes the firts list indexed at 0 from the main list i.e. the first list of the list.
del c[0] deletes the first list inside the main list indexed at 0 i.e. the first list of the list.


You Missed

Also Checkout