Searching through more than one file.

Paul Rubin no.email at nospam.invalid
Sun Dec 28 15:50:43 EST 2014


Dave Angel <davea at davea.name> writes:
> res = set()
> fnames = glob('*.txt')
> for line in fileinput.input(fnames):
>     res.update(line.rstrip().split())
> print sorted(res)

Untested:

print sorted(set(line.rstrip().split() for line in fileinput(fnames)))



More information about the Python-list mailing list