Python search a file for text using input from another file

后端 未结 5 552
梦如初夏
梦如初夏 2021-01-20 11:24

I\'m new to python and programming. I need some help with a python script. There are two files each containing email addresses (more than 5000 lines). Input file contains em

5条回答
  •  没有蜡笔的小新
    2021-01-20 11:53

    Here's what I would do:

    names=[]
    outputList=[]
    with open(inputfile) as f:
        for line in f:
            names.append(line.rstrip("\n")
    
    myEmails=set(names)
    
    with open(outputfile) as fd, open("emails.txt", "w") as output:
        for line in fd:
            for name in names:
                c=line.rstrip("\n")
                if name in myEmails:
                    print name #for console
                    output.write(name) #for writing to file
    

提交回复
热议问题