-1

How can I delete a value, for example John, out of the dictionary?

data = {'Player': ['John','Steffen'], age: [25,26]} 
data.pop("Player","John")

I just can’t find how I can delete a key like Player.

quamrana
  • 37,849
  • 12
  • 53
  • 71

2 Answers2

1

I believe you are trying to remove "John" from the list stored in the dictionary. You first have to get a reference to that list, this can be done with the "Player" key. Then you can use the remove method of the list class to remove an item from it.

An example I think solves your problem is

data = {'Player': ['John','Steffen'], age: [25,26]} 
data['Player'].remove('John') # First reference the list, then remove an item from it

I'd take a guess and say the list of ages corresponds to the list of players, so you'd have to also remove John's age from there.

JonasUJ
  • 108
  • 1
  • 6
0

You can delete a key and its values from dictionaries like this: del data['Player']

quamrana
  • 37,849
  • 12
  • 53
  • 71
Paddy Harrison
  • 1,808
  • 1
  • 8
  • 21
  • https://stackoverflow.com/questions/5844672/delete-an-element-from-a-dictionary – AMC May 11 '20 at 20:56