I have a dictionary and I want to convert every value to utf-8. This works, but is there a "more pythonic" way?
for key in row.keys():
row[key] = unicode(row[key]).encode("utf-8")
For a list I could do
[unicode(s).encode("utf-8") for s in row]
but I'm not sure how to do the equivalent thing for dictionaries.
This is different from Python Dictionary Comprehension because I'm not trying to create a dictionary from scratch, but from an existing dictionary. The solutions to the linked question do not show me how to loop through the key/value pairs in the existing dictionary in order to modify them into new k/v pairs for the new dictionary. The answer (already accepted) below shows how to do that and is much clearer to read/understand for someone who has a task similar to mine than the answers to the linked related question, which is more complex.