Skip to content

Instantly share code, notes, and snippets.

@dtaivpp
Last active October 10, 2019 20:26
Show Gist options
  • Save dtaivpp/182dbcc514ff939b6685eaaae5994afa to your computer and use it in GitHub Desktop.
Save dtaivpp/182dbcc514ff939b6685eaaae5994afa to your computer and use it in GitHub Desktop.
# Initialization
dictionary = {'string key': "string value",
('tuple', 'key'): {'dict': "value"},
123: "Value for int key"}
# Assign a key a new value
dictionary[123] = "New Value"
# Retrieve all keys from a dictionary
keys = dictionary.keys()
print(keys)
#>>> dict_keys(['string key', ('tuple', 'key'), 123])
# Retrieve all values from dictionary
values = dictionary.values()
print(values)
#>>> dict_values(['string value', {'dict': "value"}, 'New Value'])
# The items method returns an iterable object for traversing
for key, value in dictionary.items():
print("Key: {}, Value: {}".format(key, value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment