How to fill in a dictionary with key and value from a string?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Apr 1 22:02:55 EDT 2018


On Sun, 01 Apr 2018 20:52:35 -0400, C W wrote:

> Thank you all for the response.
> 
> What if I have myDict = {'a': 'B', 'b': 'C',...,'z':'A' }? So now, the
> values are shift by one position.
> 
> key:    abcdefghijklmnopqrstuvwxyz
> value: BCDEFGHIJKLMNOPQRSTUVWXYZA
> 
> Can I fill in a key and its corresponding value simultaneously on the
> fly?

Of course.

myDict = dict(zip("abcdefghijklmnopqrstuvwxyz", 
"BCDEFGHIJKLMNOPQRSTUVWXYZA"))



-- 
Steve




More information about the Python-list mailing list