Back
I have a list:
my_list = ['element1\t0238.94', 'element2\t2.3904', 'element3\t0139847']
How can I delete the \t and everything after to get this result:
['element1', 'element2', 'element3']
You can try doing something like this:
>>> l = ['element1\t0238.94', 'element2\t2.3904', 'element3\t0139847']>>> [i.split('\t', 1)[0] for i in l]['element1', 'element2', 'element3']
>>> l = ['element1\t0238.94', 'element2\t2.3904', 'element3\t0139847']
>>> [i.split('\t', 1)[0] for i in l]
To split a element from a list you can use the below-mentioned code:-
myList = [i.split('\t')[0] for i in myList]
31k questions
32.8k answers
501 comments
693 users