x = ['Some strings.', 1, 2, 3, 'More strings!', 'Fanc\xc3\xbf string!']
y = [i.decode('UTF-8') for i in x]
What's the best way to convert the strings in x to Unicode? Doing a list compression causes an attribute error (AttributeError: 'int' object has no attribute 'decode'
) because int's don't have a decode method.
I could use a for loop with a try? Or I could do some explicit type checking in the list compression, but is type checking in a dynamic language like Python the right approach?
UPDATE:
I would prefer that the int's remain int's. Although this is not a strict requirement. My ideal output would be [u'Some strings.', 1, 2, 3, u'More strings!', u'Fancÿ string!']
.