PYTHON. One pill is enough
- nalatty80
- Nov 7, 2022
- 1 min read
The simplest code and a significant difference in details:
import re
x = 'My 2 favourine numbers are 19 and 42'
y = re.findall('[0-9]', x)
print(y)
The result in the first case looks like this:
['2', '1', '9', '4', '2']
It broke the numbers into single digits, converting "19" and "42" into "1," "9," "4", and "2."
We add a plus sign to the expression in square brackets and, voila:
import re
x = 'My 2 favourine numbers are 19 and 42'
y = re.findall('[0-9]+', x)
print(y)
The code solution now looks like this:
['2', '19', '42']
This is such nonsense, kids.
(Nata fights with codes and masters Python step by step.)
Comments