# name: 04hanzi.py
# date: 20240609
# programmer: arithmus
# memo: find hanzi string
import re
def is_in(fullstr,substr):
if re.findall(substr,fullstr):
return 1
else:
return 0
a = '這個暑假我讀了紅樓夢和三國演義'
b= ['三國演義','水滸傳','西遊記','紅樓夢']
line = []
n = 0
for i in b:
num = is_in(a,i)
n += num
res = re.findall(i,a)
line = line + res
print(f'四大名著暑假讀了{n}本')
print(f'分別是{line}')
'''
res = re.findall(i,a) re.findall返回值是一個列表
out:
四大名著暑假讀了2本
分別是['三國演義', '紅樓夢']
'''