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

3 answers 153 views
1 answer 223 views
1 answer 134 views
2 answers 236 views
1 answer 177 views
...