Easy way to convert a unicode list to a list containing python strings? -


template of list is:

employeelist =  [u'<empid>', u'<name>', u'<doj>', u'<salary>'] 

i convert this

employeelist =  [u'1001', u'karick', u'14-12-2020', u'1$'] 

to this:

employeelist =  ['1001', 'karick', '14-12-2020', '1$'] 

after conversion, checking if "1001" exists in employeelist.values().

encode each value in list string:

[x.encode('utf8') x in employeelist] 

you need pick valid encoding; don't use str() that'll use system default (for python 2 that's ascii) not encode possible codepoints in unicode value.

utf-8 capable of encoding of unicode standard, codepoint outside ascii range lead multiple bytes per character.

however, if want test specific string, test unicode string , python won't have auto-encode values when testing that:

u'1001' in employeelist.values() 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -