You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何统计字符串中含翻转数字在内的各数字出现次数?

统计含翻转变体的数字出现次数

首先明确普通数字和对应翻转变体的映射关系(基于你的示例):

  • 1 ↔ І
  • 2 ↔ ᘔ
  • 3 ↔ Ɛ
  • 4 ↔ ᔭ

你可以通过以下方式实现包含翻转变体的次数统计:

完整代码示例

stri = "1234 ᔭƐᘔІ "
# 建立数字与翻转变体的映射字典
flip_mapping = {
    '1': 'І',
    '2': 'ᘔ',
    '3': 'Ɛ',
    '4': 'ᔭ'
}

# 遍历统计每个数字的总出现次数
for num, flip_char in flip_mapping.items():
    total_count = stri.count(num) + stri.count(flip_char)
    print(f"Number of {num}'s in str = {total_count}")

运行结果

Number of 1's in str = 2
Number of 2's in str = 2
Number of 3's in str = 2
Number of 4's in str = 2

如果后续遇到其他数字的翻转变体,只需在flip_mapping字典中补充对应的键值对即可,扩展性很强。

内容的提问来源于stack exchange,提问作者Cookie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 19:01:03