How to extract numbers from string into a list with Python

1 Answer

0 votes
s = "python 3 c++ 17 'php 7"

lst = [int(c) for c in s.split() if c.isdigit()] 

print(lst)


'''
run:

[3, 17, 7]

'''

 



answered Jan 21, 2020 by avibootz

Related questions

1 answer 244 views
3 answers 189 views
1 answer 163 views
2 answers 251 views
1 answer 198 views
...