Skip to Content
Secret Recipes of the Python Ninja
book

Secret Recipes of the Python Ninja

by Cody Jackson
May 2018
Intermediate to advanced content levelIntermediate to advanced
380 pages
9h 37m
English
Packt Publishing
Content preview from Secret Recipes of the Python Ninja

Dictionaries

As mappable objects, dictionaries have a number of built-in methods, as they cannot use the normal sequence operations (note: d represents a dictionary, key is a particular key for the dictionary, and value is the value associated with a key):

  • len(d): This returns the number of items in a dictionary.
  • d[key]: This return the value associated with key.
  • d[key] = value: This is used to set the mapping of key to value.
  • del d[key]: This deletes the value associated with key.
  • key in d: If key exists in the dictionary, return True; otherwise, return False.
  • key not in d: If key exists in the dictionary, return False; otherwise, return True.
  • iter(d): This returns an interator object from the dictionary keys. To actually use the iterated ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Expanding World of Python

The Expanding World of Python

Dane Hillard

Publisher Resources

ISBN: 9781788294874Supplemental Content