Add entry to beginning of list and remove the last one

后端 未结 5 2019
生来不讨喜
生来不讨喜 2020-12-16 16:40

I have a list of about 40 entries. And I frequently want to append an item to the start of the list (with id 0) and want to delete the last entry (

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-16 16:55

    Use insert() to place an item at the beginning of the list:

    myList.insert(0, "wuggah")
    

    Use pop() to remove and return an item in the list. Pop with no arguments pops the last item in the list

    myList.pop() #removes and returns "da..."
    

提交回复
热议问题