Skip to content

Instantly share code, notes, and snippets.

@ItsCosmas
Created May 8, 2019 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ItsCosmas/31a9d635bab2bfcc35633d3c807add59 to your computer and use it in GitHub Desktop.
Save ItsCosmas/31a9d635bab2bfcc35633d3c807add59 to your computer and use it in GitHub Desktop.
Dictionaries
ages = {"Cozy": 21, "Mark": 22, "Dan": 25}
primary = {
"red": [255, 0, 0],
"green": [0, 255, 0],
"blue": [0, 0, 255]
}
print(primary["red"])
print(ages["Cozy"])
# Only Immutable objects can be used as keys to dictionaries
# Dictionaries and Lists are mutable and cannot be used as keys in a dictionary
# DICTIONARY FUNCTIONS
squares = {1: 1, 2: 4, 3: "Error", 4: 16, }
print(squares)
squares[3] = 9
squares[8] = 64
print(squares)
print(4 in squares)
print(4 not in squares)
print(squares.get(9, "Not in Squares"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment