Question: In Python, Create a list of lowercase alphabetical characters. Heres some code to get you started # Create a list of lc letters the OG
In Python, Create a list of lowercase alphabetical characters. Heres some code to get you started
# Create a list of lc letters the OG way with with a list comprehension, chr(), range(), # and a knowledge of the numbers of the ASCII lowercase letters. # The trick to this method is that you have to know the ASCII decimal value of the lowercase letters! lowercase_letters = [chr(i) for i in range(97, 123)] # Another way to get the lowercase letters is to import the string module # and use the string.ascii_lowercase list, like this: # # import string # lowercase_letters = list(string.ascii_lowercase) # --------- Your code starts here ---------- #
1. Create a dictionary using the the list of letters as keys with values being the uppercase version of the letters.
2 Print all of the dictionarys keys sorted use the keys()method to retrieve the keys from the dict.
3. Print all of the values of the dictionary sorted use values() method.
4. Print all of the keys and values sorted in reverse by value.
Example output
------------------------------ The dictionary: {'g': 'G', 'o': 'O', 't': 'T', 'v': 'V', 'i': 'I', 'f': 'F', 'z': 'Z', 'w': 'W', 'h': 'H', 'n': 'N', 'm': 'M', 'q': 'Q', 'k': 'K', 'j': 'J', 'u': 'U', 'r': 'R', 'y': 'Y', 'a': 'A', 'd': 'D', 'c': 'C', 'x': 'X', 's': 'S', 'b': 'B', 'e': 'E', 'p': 'P', 'l': 'L'} ------------------------------ The sorted keys: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] ------------------------------ The sorted values: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] The current state of the dict {'g': 'G', 'o': 'O', 't': 'T', 'v': 'V', 'i': 'I', 'f': 'F', 'z': 'Z', 'w': 'W', 'h': 'H', 'n': 'N', 'm': 'M', 'q': 'Q', 'k': 'K', 'j': 'J', 'u': 'U', 'r': 'R', 'y': 'Y', 'a': 'A', 'd': 'D', 'c': 'C', 'x': 'X', 's': 'S', 'b': 'B', 'e': 'E', 'p': 'P', 'l': 'L'} The dict reverse sorted and printed by value: z:Z y:Y x:X w:W v:V u:U t:T s:S r:R q:Q p:P o:O n:N m:M l:L k:K j:J i:I h:H g:G f:F e:E d:D c:C b:B a:A Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
