Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
68 views
in Technique[技术] by (71.8m points)

python - How to split elements of a list?

I have a list:

my_list = ['element10238.94', 'element22.3904', 'element30139847']

How can I delete the and everything after to get this result:

['element1', 'element2', 'element3']
Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Something like:

>>> l = ['element10238.94', 'element22.3904', 'element30139847']
>>> [i.split('', 1)[0] for i in l]
['element1', 'element2', 'element3']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...