求一长串数字中出连续出现最多的数,不是出现频率最高的数
比如:277230077000877 返回0而不是7,因为0连续出现最多的一次是3比7多。
322213133 返回2
不能用string、list做,只能用loop
python:求一长串数字中出连续出现最多的数
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- threenewbee 2020-09-11 16:08关注
# -*- coding: UTF-8 -*- import re s = "277230077000877" matches = re.finditer(r'(\d)\1{1,}',s) results = list([match.group(0) for match in matches]) results.sort(key=lambda x: -len(x)) print(results[0][0])
0
不同string list用循环:
import re s = "277230077000877" matches = re.finditer(r'(\d)\1{1,}',s) ma = "" for match in matches: if len(ma) < len(match.group(0)): ma = match.group(0) print(ma[0])
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 keil的map文件中Image component sizes各项意思
- ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
- ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
- ¥15 划分vlan后,链路不通了?
- ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
- ¥15 Vue3 大型图片数据拖动排序
- ¥15 Centos / PETGEM
- ¥15 划分vlan后不通了
- ¥20 用雷电模拟器安装百达屋apk一直闪退
- ¥15 算能科技20240506咨询(拒绝大模型回答)