How to delete list item automatically in python?

  • A+

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?


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] 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: