python 2.7 - Replace specific character from the list of string -


gurus,

i have list looks following :

[u'test1', u'test2', '', ''] 

i trying find way replace character u before 'test1' , 'test2' none ''. after replacing like:

['test1','test2', '', ''] 

initially had list following:

[u'test1\n', u'test2\r\n', '', ''] 

this reduce using following:

row_val = [w.replace('\n', '') w in row_val] row_val = [w.replace('\r', '') w in row_val] 

let me know there way perform same without iterating through each string.

the u not string character, telling unicode object rather str object.

you can do:

row_val = [str(w) w in row_val] 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -