Deleting a few list items inside of dictionary

前端 未结 5 1934
余生分开走
余生分开走 2021-01-27 13:55

Deleting a few list items inside of dictionary

Hi, I have a dictionary:

phone = {\"first\":100,\"second\":200,\"third\":[10,12,5,38],\"fourth\":400}
         


        
5条回答
  •  再見小時候
    2021-01-27 14:37

    You can treat phone["third"] as a list since that is what it evaluates to. For instance, if you know the indexes of the items you want to remove you can do:

    phone["third"][1:3]=[]
    

    or

    del phone["third"][1:3]
    

提交回复
热议问题