0 Pluspunkte 0 Minuspunkte

Wie kann ich einen Eintrag aus einem Python Dictionary entfernen?

mydict = {"name": "thomas", "planet": "arcadia", "resources": [20, 100, 87, 44], "weapons": [0, 0.23, 0.89, 0.29, 0.95]}

Wie kann ich z.B den kompletten Speicher von "weapons" entfernen so das es am Ende so aussieht?

mydict = {"name": "thomas", "planet": "arcadia", "resources": [20, 100, 87, 44]}
von  

2 Antworten

0 Pluspunkte 0 Minuspunkte

Mit

mydict.pop("weapons")
von  
0 Pluspunkte 0 Minuspunkte

Du kannst einen Eintrag mit dem "del" Statement entfernen.

del mydict["weapons"]
von (716 Punkte)