Question 6.14: Removing Things from a Dictionary You need to remove an item......

Removing Things from a Dictionary

You need to remove an item from a dictionary.

Step-by-Step
The 'Blue Check Mark' means that this solution was answered by an expert.
Learn more on how do we answer questions.

Use the pop command, specifying the key for the item that you want to remove:

>>> phone_numbers = {‘Simon’:’01234 567899′, ‘Jane’:’01234 666666′}
>>> phone_numbers.pop(‘Jane’)
‘01234 666666’
>>> phone_numbers
{‘Simon’: ‘01234 567899’}

Discussion

The pop command returns the value of the item removed from the dictionary.

See Also

All the recipes between Recipes 6.12 and 6.15 involve the use of dictionaries.

Related Answered Questions

Question: 6.15

Verified Answer:

Use the for command to iterate over the keys of th...
Question: 6.11

Verified Answer:

Use the Python language feature called comprehensi...
Question: 6.13

Verified Answer:

Use the Python [] notation. Use the key of the ent...
Question: 6.12

Verified Answer:

Use a Python dictionary. Arrays are great when you...
Question: 6.10

Verified Answer:

Use the [:] Python language construction. The foll...
Question: 6.9

Verified Answer:

Use the sort Python language command: >>&...
Question: 6.7

Verified Answer:

Use the for Python language command: >>&g...
Question: 6.2

Verified Answer:

Use the [] notation to access elements of a list b...
Question: 6.3

Verified Answer:

Use the len Python function. For example: >&...