I want to remove 'u' from every element in the list, can anybody help me?
[u'four', u'gag', u'prefix', u'woods']
I want to remove 'u' from every element in the list, can anybody help me?
[u'four', u'gag', u'prefix', u'woods']
The issue is with the encoding of strings. Do this :
l = [u'four', u'gag', u'prefix', u'woods']
l2 = [i.encode('UTF-8') for i in l]
print l2
['four', 'gag', 'prefix', 'woods']
The u is an attribute that tells what type of string it is. If it was a byte string, this would be b. If you call type on these, they will return String. The difference between Unicode and something like ASCII is that Unicode is a super-set of ASCII that is the same for 0-127, but has more capability to represent different types of characters. These can be UTF-8 or UTF-32 or whatever, but generally are larger than one byte.
It should behave the same for 99% of the things that you want to do, but you can also change the encoding if you have a function that needs a very particular type of string.