python – How to split elements of a list?

python – How to split elements of a list?

Something like:

>>> l = [element1t0238.94, element2t2.3904, element3t0139847]
>>> [i.split(t, 1)[0] for i in l]
[element1, element2, element3]
myList = [i.split(t)[0] for i in myList] 

python – How to split elements of a list?

Try iterating through each element of the list, then splitting it at the tab character and adding it to a new list.

for i in list:
    newList.append(i.split(t)[0])

Leave a Reply

Your email address will not be published.