Skip to content Skip to sidebar Skip to footer

Remove Text:u From Strings In Python

I am using xlrd library to import values from excel file to python list. I have a single column in excel file and extracting data row wise. But the problem is the data i am getting

Solution 1:

Iterate over items and remove extra characters from each word:

s=[]   
for x in list:
    s.append(x[7:-1]) # Slice from index 7 till lastindex - 1

Solution 2:

If that's the standard input list you have, you can do it with simple split

[s.split("'")[1] for s inlist]

# if your string itself has got "'" in between, using regex is always safeimport re
[re.findall(r"u'(.*)'", s)[0] for s inlist]

#Output#['__string__', '__string__']

Solution 3:

I had the same problem. Following code helped me.

list = ["text:u'__string__'","text:u'__string__'",.....so on]
forindex, item in enumerate(list):
      list[index] = list[index][7:] #Deletes first 7 xharacters
      list[index] = list[index][:-1] #Deletes last character

Post a Comment for "Remove Text:u From Strings In Python"