python - Deleting a few list items inside of dictionary -
deleting few list items inside of dictionary
hi, have dictionary:
phone = {"first":100,"second":200,"third":[10,12,5,38],"fourth":400}
let' want remove 12 , 5 from "phone" dictionary. there way using "del" function?
i know how this, using .remove()
phone["third"].remove(12) phone["third"].remove(5)
but wondering if possible using del()? thank you.
edit: replies concentrating on "del uses index, remove uses exact value", redefining question:
i want delete indexes 1 , 2 in list representing third key-value item in "phone" dictionary. how can that?
you have index rather value:
>>> phone = {"first":100,"second":200,"third":[10,12,5,38],"fourth":400} >>> del(phone["third"][1:3]) >>> phone {'second': 200, 'fourth': 400, 'third': [10, 38], 'first': 100}
this deletes elements in position 1 , 2 in list.
Comments
Post a Comment