1. 首页
  2. 数据库
  3. 其它
  4. Python CCF:20191203 化学方程式(使用正则表达式re库)

Python CCF:20191203 化学方程式(使用正则表达式re库)

上传者: 2021-01-03 15:00:09上传 PDF文件 59.52KB 热度 12次
题目链接 为了降低难度。以下分别为,只考虑大小写字母和等号的方程组、加入数字、加入括号(非嵌套) import re def cnt(string: str): pattern = r"[A-Z][a-z]*" #匹配元素 elements = re.findall(pattern, string) count = {} # 统计元素词频 for item in elements: if item in count: count[item] += 1 else: count
下载地址
用户评论