python案例,找出单词并输出行号

import re
wordname = input("Enter the new Shop Name: ")
with open('password.txt','r') as f:
    lines = f.readlines()
    for idx,line in enumerate(lines,1):
        if re.search(wordname, line):
            print(idx,line)

 

yield x
from itertools import islice
for x in islice(items,3,None):

from itertools import dropwhile
for line in dropwhile(lambda line:line.startswith(#),f)

line.startswith('#')
lines=(line for line in f if not line.startswith('#'))

去除#号开头

 

posted on 2021-07-09 14:18  星期六男爵  阅读(168)  评论(0编辑  收藏  举报

导航