Reputation: 11
How to create a dictionary using the list of letters as keys with values being the uppercase version of the letters.
Upvotes: 1
Views: 430
Reputation: 1468
Using a dict comprehension with all of your chosen letters will give you key:value pairs with 'lower':'UPPER'.
lower_to_upper = {
letter: letter.upper()
for letter in 'abcdefghijklmnopqrstuvwxyz'
}
Upvotes: 2
Reputation: 3817
Use a list comprehension to build tuples that are input to create the dictionary.
mylist = ['a', 'b', 'c']
dict((i, i.upper()) for i in mylist)
output
{'a': 'A', 'b': 'B', 'c': 'C'}
Upvotes: 0