On 2018-03-30 21:13, C W wrote:
Hello all,

I want to create a dictionary.

The keys are 26 lowercase letters. The values are 26 uppercase letters.

The output should look like:
{'a': 'A', 'b': 'B',...,'z':'Z' }

I know I can use string.ascii_lowercase and string.ascii_uppercase, but how
do I use it exactly?
I have tried the following to create the keys:

myDict = {}
         for e in string.ascii_lowercase:
             myDict[e]=0

But, how to fill in the values? Can I do myDict[0]='A', myDict[1]='B', and
so on?

The uppercase equivalent of what's in "e" is "e.upper()". Does that help?

Alternatively, string.ascii_lowercase will give you the keys and string.ascii_uppercase will give you the values for a dict; use "zip" to make them into pairs (2-tuples) and then pass the list/generator into "dict":

dict(zip(string.ascii_lowercase, string.ascii_uppercase))
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to