python extract all numbers from string re
>>> str = "h3110 23 cat 444.4 rabbit 11 2 dog"
>>> [int(s) for s in str.split() if s.isdigit()]
[23, 11, 2]
python extract all numbers from string re
>>> str = "h3110 23 cat 444.4 rabbit 11 2 dog"
>>> [int(s) for s in str.split() if s.isdigit()]
[23, 11, 2]
extract digits with serten lenth from string python
import re
str = 'We four guys, live at 2nd street of Malibeu 521. I had a cash of $248 in my pocket. I got a ticket with serial number 88796451-52.'
#search using regex
x = re.findall('[0-9]+', str)
print('All Numbers\n',x)
#digits of length N
N=3
def filterNumber(n):
if(len(n)==N):
return True
else:
return False
#filter the list
finalx = list(filter(filterNumber, x))
print('Final List\n',finalx)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us