添加从题库中选择指定年级功能select_grade_from_pro_dict
This commit is contained in:
parent
e78a778326
commit
c8499d4199
|
|
@ -1234,5 +1234,29 @@ def SubstringOccurence(regex,string): #生成regex在string中出现的所有位
|
||||||
poslist = [item.start() for item in re.finditer(regex,string)]
|
poslist = [item.start() for item in re.finditer(regex,string)]
|
||||||
return poslist
|
return poslist
|
||||||
|
|
||||||
|
def select_grade_from_pro_dict(prodict,grades):
|
||||||
|
if len(grades) == 0:
|
||||||
|
return prodict
|
||||||
|
else:
|
||||||
|
gradelist = []
|
||||||
|
for g in grades:
|
||||||
|
if not "届" in g:
|
||||||
|
gradelist.append(g+"届")
|
||||||
|
else:
|
||||||
|
gradelist.append(g)
|
||||||
|
adict = prodict.copy()
|
||||||
|
for id in prodict:
|
||||||
|
raw_usages = prodict[id]["usages"].copy()
|
||||||
|
new_usages = []
|
||||||
|
for u in raw_usages:
|
||||||
|
for g in gradelist:
|
||||||
|
if g in u:
|
||||||
|
new_usages.append(u)
|
||||||
|
adict[id]["usages"] = new_usages.copy()
|
||||||
|
return adict
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("数据库工具, import用.")
|
print("数据库工具, import用.")
|
||||||
Reference in New Issue