how to convert list of dictionary into string python

user7642164

Example is given below this is the list that contains so many dictionaries

l = [{'ID': '4901454'}, {'ID': '5722619'}, {'ID': '5722619'}]

Expected output string is

>>> result = '4901454,5722619,5722619'

Any help would be appreciated

Chris Doyle

You can use a list comprehension to iterate over the dicts in the list and for each dict get the value for the id and then with the returning list of id vals join them with a comma.

data = [{'ID': '4901454'}, {'ID': '5722619'}, {'ID': '5722619'}]
string = ",".join([item['ID'] for item in data])
print(string)

OUTPUT

4901454,5722619,5722619

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to convert a dictionary to query string in Python?

How to convert values of a dictionary list into string?

How to convert List<string> to Dictionary<string,string> using linq?

How to convert a list of tuples to a dictionary of dictionaries in Python?

How to convert python list to python dictionary with sequence

How to convert String values in a dictionary to a list in python?

How to convert list of string to dictionary in python

Convert String representation of a List to a Dictionary Python

How to convert list of string to list of dictionary in Python

How to convert dictionary list to custom objects in Python

How to convert list to dictionary in python with key value?

Python - How to convert dictionary alike string to dictionary

How to convert string to dictionary into python

python dictionary and list: how to convert it?

Convert String to Python List of Dictionary

How convert list of dictionaries to a dictionary of dictionaries in Python

How to convert `Dictionary<string, Dictionary<string, List<MyCustomClass>>>` to `Dictionary<string, List<MyCustomClass>> `

How to convert list of list to dictionary in Python?

convert unequaled length list of string to dictionary python

Python 3 - How to convert a string to a list of dictionary

How to convert unciode to list of dictionary in python

how to convert string list dictionary to list

How do I convert list into dictionary in Python?

How to convert a String to a dictionary list

How to convert nested dictionary into the string of list

How to convert Python dataclass to dictionary of string literal?

how to convert a list to dictionary in python?

How to convert a string dictionary to dictionary in python?

How to convert list to dictionary in Python?