Say I have a mixed list of dictionaries with strings and integers as values and I want to convert the integers to strings, how should one do that without going all over the place and converting them one by one considering that the list is fluid, long and might also change some of the existing values to integers.
Example:
list = [{'a':'p', 'b':2, 'c':'k'},
{'a':'e', 'b':'f', 'c':5}]
Now if I'll try and print the values of the list with a string it will give me an error as follows.
Example:
for x in list:
print('the values of b are: '+x['b'])
Output:
TypeError: can only concatenate str (not "int") to str
Process finished with exit code 1
Any help is appreciated, Thanks!
SOLUTION
list = [{'a':'p', 'b':2, 'c':'k'},
{'a':'e', 'b':'f', 'c':5}]
for dicts in list:
for keys in dicts:
dicts[keys] = str(dicts[keys])
print('the values of b are: '+ dicts["b"])