I have a list like this
d=[{u'Length': u'2.96m', u'Width': u'1.44m', u'height': u'0.38m'},
{u'Length': u'3.8m', u'Width': u'0.65m', u'height': u'9.3m'},
{u'Length': u'0.62m', u'Width': u'2.9m', u'height': u'3.5m'}]
and I want a simple way to remove unicode 'u' from this list to create a new list. The "simple way" here I ment to remove unicode without importing an external module or saving it in external files.
These are the five methods I tried
def to_utf8(d):
if type(d) is dict:
result = {}
for key, value in d.items():
result[to_utf8(key)] = to_utf8(value)
elif type(d) is unicode:
return d.encode('utf8')
else:
return d
#these three returns AttributeError: 'list' object has no attribute 'encode'
d.encode('utf-8')
d.encode('ascii')
d.encode("ascii","replace")
#output the same
to_utf8(d)
print str(d)
firs three returns
AttributeError: 'list' object has no attribute 'encode'
and last two prints the same result. How should I remove unicode 'u'?