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

C W tmrsg11 at gmail.com
Sun Apr 1 22:24:31 EDT 2018


Thank you Steven. I am frustrated that I can't enumerate a dictionary by
position index.

Maybe I want to shift by 2 positions, 5 positions...

I want to know/learn how to manipulate dictionary with loop and by its
position location.



On Sun, Apr 1, 2018 at 10:02 PM, Steven D'Aprano <
steve+comp.lang.python at pearwood.info> wrote:

> 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
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>


More information about the Python-list mailing list