LeetCode | 判断子串下标
通过正则查找返回下标
import re master = "AVERDXIVYERDIAN" dev = "ERD" for m in re.findall(f"{dev}", master): print(m) list = [m.start() for m in re.finditer(f"{dev}", master)] print(list) if list: if list[0] + 1 >= 0: print(list[0] + 1) else: print("No") else: print("No")