Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

convert a list to dictionary by using formkeys with different values

can I have a list that I use formkeys to convert it into a dictionary and the values of the dictionary be their indexes of the list?

for example my list is ["a", "b", "c", "d", "e"]

and if I use formkeys, I want it will be {"a" :0 , "b" :1 , "c" :2 , "d" :3 , "e" :4 }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

could you tell me how can I do it?

or if you know another way that it’s order is less than this way (in python), please tell me.

>Solution :

Suppose lst = ['a', 'b', 'c' ...]:

dict = {a: b for b,a in enumerate(lst)}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading