【问题标题】:Extract maximum numeric value from given string从给定字符串中提取最大数值
【发布时间】:2019-04-02 17:44:43
【问题描述】:

给定一个字母数字字符串S,从该字符串中提取最大数值。所有的字母都是小写的。将最大连续位数作为一个数字。

示例输入:23dsa43dsa98
预期输出:98

我试过了:

import re
a=input()
item=([re.split(r'(\d+)', s) for s in (a)])
print(item)

【问题讨论】:

    标签: python python-3.x string max python-re


    【解决方案1】:

    这可行:

    max(re.findall('\d+', a), key = lambda x: int(x))
    

    【讨论】:

      【解决方案2】:

      试试:

      res = re.findall(r'\d+', a)
      max(list(map(int, res)))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-29
        • 2015-06-21
        • 1970-01-01
        • 2021-06-23
        • 2019-11-20
        相关资源
        最近更新 更多