top of page

PYTHON. One pill is enough

  • Writer: nalatty80
    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


Natalia Chesnova

+1 352 638 4257 (USA)

+38 050 475 1469 (UA)

nalatty80@gmail.com

© 2022 by nalatty

  • Facebook
  • Twitter
  • Instagram
  • YouTube
bottom of page