[英]Extract maximum numeric value from given string
Given an alphanumeric string S
, extract maximum numeric value from that string.给定一个字母数字字符串
S
,从该字符串中提取最大数值。 All the alphabets are in lower case.所有的字母都是小写的。 Take the maximum consecutive digits as a single number.
将最大的连续数字作为一个数字。
Example Input: 23dsa43dsa98
示例输入:
23dsa43dsa98
Expected Output: 98
预期输出:
98
I tried:我试过:
import re
a=input()
item=([re.split(r'(\d+)', s) for s in (a)])
print(item)
这会起作用:
max(re.findall('\d+', a), key = lambda x: int(x))
Try:尝试:
res = re.findall(r'\d+', a)
max(list(map(int, res)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.