+ 4
Alphanumeric string
How to find max number occuring in alphanumeric string? Ex:- input ='23dy10jp98' Output=98
2 Réponses
+ 12
I'd use regular expressions.
import re
s = '23dy10jp98'
pattern = re.compile(r'\d+')
print(max([int(n) for n in pattern.findall(s)])) # output: 98
+ 6
A way without re:
s = '23dy10jp98'
s = ''.join([d if d.isdigit() else ' '
for d in s ])
print(max([int(n) for n in s.split()]))