zoukankan      html  css  js  c++  java
  • 从字符串中找出最大的数字串,字符串中可以带小数点。--python实现

     1 import re
     2 input_str = "abcd123.4567.891.123yfdsa4567.54"
     3 # 使用正则找出所有数字及下标
     4 pattern = re.compile(r"d+")
     5 s = pattern.finditer(input_str)
     6 tmp = []
     7 for i in s:
     8     tmp.append((i.group(), i.regs[0]))
     9 # 求出最大的数及对应下标
    10 max_int = max(map(int, [c[0] for c in tmp]))
    11 tmp = [i for i in tmp if i[0]==str(max_int)]
    12 print(tmp)
    13 find = []
    14 for t in tmp:
    15     inx = t[1][1]
    16     xiaoshu = ""
    17     _f = t[0]
    18     if len(input_str) != inx and input_str[inx] == ".":
    19         _inx = inx
    20         for c in range(len(input_str[inx+1:])):
    21             if input_str[_inx+1].isdigit():
    22                 _inx += 1
    23             else:
    24                 break
    25         xiaoshu = input_str[inx+1:_inx+1]
    26         print("xiaoshu:", xiaoshu)
    27     if xiaoshu:
    28         _f = t[0] + "."+xiaoshu
    29     find.append(_f)
    30 print("===========")
    31 find = max(map(float, find))
    32 print(find)
  • 相关阅读:
    帆软报表实现全选全不选的功能
    knowledge_others
    skills_kafka
    skills_operation
    problems_others
    skills_windows
    c语言标识符
    快速排序法
    字符串处理scanf("%d%*c",&n);
    Byte.parseByte(String s,int radix)的解释
  • 原文地址:https://www.cnblogs.com/liown/p/12144712.html
Copyright © 2011-2022 走看看