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

how to add an Id to each row in dictionary ? python

I want to change my data from a dictionary without id’s to [(id,’string’),(id2,’string 2′),…]
Data transformation

>Solution :

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

Your "mydictionary" is a set inside of a list:

mydictionary = [{'errors', 'wonderful'}]
mydictionary = mydictionary[0]  # now is just a set (out of the list)
# Then we "unpack" with a list comprehension
wanted_dictionary = [ (i,key) for i,key in enumerate(mydictionary)]
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