-1

I currently have this right now

[{'label': 'ID', 'value': '8'}, {'label': 'Document', 'value': 'Authority Visit'}]

I wanted it to be

[{'ID':'8'},{'Document':'Authority Visit'}]

Thanks for helping.

Calvin Tey
  • 41
  • 7
  • Possible duplicate of [python getting a list of value from list of dict](https://stackoverflow.com/questions/7271482/python-getting-a-list-of-value-from-list-of-dict) – orde Jan 04 '19 at 06:24
  • 3
    Why do you want a list of single element dicts? – Stephen Rauch Jan 04 '19 at 06:33
  • Going off of @StephenRauch, I think it might be more constructive to create _one_ dictionary with `'ID'` and `'Document'` as your keys. – busybear Jan 04 '19 at 06:37

1 Answers1

2

You can just iterate over your list and then access both label and values per item:

sample_dict = [
  {'label': 'ID', 'value': '8'},
  {'label': 'Document', 'value': 'Authority Visit'}
]

result = [{item['label']:item['value']} for item in sample_dict]

print(result)
fixatd
  • 1,394
  • 1
  • 11
  • 19