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

时间:2021-07-09 16:49:57   收藏:0   阅读:20
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(#))

去除#号开头

 

原文:https://www.cnblogs.com/long2-20160310/p/14990368.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!