Last active
October 10, 2019 20:26
-
-
Save dtaivpp/182dbcc514ff939b6685eaaae5994afa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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