Last active
June 16, 2020 02:24
-
-
Save bryanmobrien/db91e380a5117ce87c4640e202f7f092 to your computer and use it in GitHub Desktop.
This file contains 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
verse_dict = { 'if': 3, 'you': 6, 'can': 3, 'keep': 1, 'your': 1, 'head': 1, | |
'when': 2, 'all': 2, 'about': 2, 'are': 1, 'losing': 1, 'theirs': 1, | |
'and': 3, 'blaming': 1, 'it': 1, 'on': 1, 'trust': 1, 'yourself': 1, | |
'men': 1, 'doubt': 1, 'but': 1, 'make': 1, 'allowance': 1, 'for': 1, | |
'their': 1, 'doubting': 1, 'too': 3, 'wait': 1, 'not': 1, 'be': 1, | |
'tired': 1, 'by': 1, 'waiting': 1, 'or': 2, 'being': 2, 'lied': 1, | |
'don\'t': 3, 'deal': 1, 'in': 1, 'lies': 1, 'hated': 1, 'give': 1, | |
'way': 1, 'to': 1, 'hating': 1, 'yet': 1, 'look': 1, 'good': 1, | |
'nor': 1, 'talk': 1, 'wise': 1} | |
print(verse_dict, '\n') | |
# find number of unique keys in the dictionary | |
num_keys = len(set(val for keys in verse_dict for val in verse_dict.keys())) | |
print("Number of unique keys is: " + str(num_keys)) | |
# find the number of unique values in the dictionary | |
num_values = len(set(val for values in verse_dict for val in verse_dict.values())) | |
print("Number of unique values is: " + str(num_values)) | |
# find whether 'breathe' is a key in the dictionary | |
contains_breathe = ('breathe' in verse_dict) | |
print(contains_breathe) | |
# create and sort a list of the dictionary's keys | |
sorted_keys = sorted(verse_dict.keys()) | |
sorted_values = sorted(verse_dict.values()) | |
print("The keys, sorted: \n" + str(sorted_keys)) | |
print("The values, sorted: \n" + str(sorted_values)) | |
# get the first element in the sorted list of keys | |
print("The first key in the sorted list of keys is: " + sorted_keys[0]) | |
print("The first value in the sorted list of values is: " + str(sorted_values[0])) | |
# find the element with the highest value in the list of keys | |
print("The element with the highest value in the list of keys is: " + max(sorted_keys)) | |
print("Bonus: The first key in verse_dict is: " + list(verse_dict.keys())[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment