If i have a list
for example :
num=[1,2,3,4]
and i want to delete
list[0]
every 2 second, so after 2 second list in num is num = [2,3,4]
and 2 second after it will be num =[2,3]
how can i do that?
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.
In Python, use list methods clear() , pop() , and remove() to remove items (elements) from a list. It is also possible to delete items using del statement by specifying a position or range with an index or slice.
The remove() function removes the first matching value from the list. The pop() function is used to return the removed element from the list. The del() function is used to delete an element at a specified index number in the list.
You could do it using time.sleep
, and del
to remove the first element:
for i in range(len(num)):
time.sleep(2)
del num[0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With