5

I have a list of strings. I want to convert to dictionary. I got the output after scraping the data.

['Name:Dr. Mak', 'Location: India, Delhi']
['Name:Dr. Hus MD', 'Location:US, NY']

I want Output like below

{'Name':'Dr. Mak', 'Location': 'India, Delhi'}
{'Name':'Dr. Hus MD', 'Location':'US, NY'}

1 Answers1

11
dict(s.split(':', 1) for s in list_of_strings)

Edit: removing whitespace

dict(map(str.strip, s.split(':', 1)) for s in list_of_strings)
FHTMitchell
  • 11,793
  • 2
  • 35
  • 47