What is the cleanest way to obtain a list of the numeric values in a string?
For example:
string = 'version_4.11.2-2-1.4'
array = [4, 11, 2, 2, 1, 4]
As you might understand, I need to compare versions.
By "cleanest", I mean as simple / short / readable as possible.
Also, if possible, then I prefer built-in functions over regexp (import re
).
This is what I've got so far, but I feel that it is rather clumsy:
array = [int(n) for n in ''.join(c if c.isdigit() else ' ' for c in string).split()]
Strangely enough, I have not been able to find an answer on SO:
- In this question, the input numeric values are assumed to be separated by white spaces
- In this question, the input numeric values are assumed to be separated by white spaces
- In this question, the user only asks for a single numeric value at the beginning of the string
- In this question, the user only asks for a single numeric value of all the digits concatenated
Thanks