[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Größte Schnittmenge von mehreren Dateien

Moin Tilo!
Tilo Schwarz schrieb am Sonntag, den 07. August 2005:

> Oder:
> from sys import stdout
> from sets import Set
> files = ["/tmp/pc1.pkgs", "/tmp/pc2.pkgs"]
> sets = [Set(file(f).readlines()) for f in files]
> intersection = reduce(lambda x,y: x & y, sets)
> stdout.writelines(intersection)

Viel zu lang, und langsamer als

perl -ne 'print $_ if $seen{$_}; $seen{$_}=1' file1 file2

(selbst mit psyco).

The past tempts us, the present confuses us, the future frightens us.
And our lives slip away, moment by moment, lost in the terrible
in-between.    -- Centauri Emperor, "Babylon 5 - The Coming Of Shadows"

Reply to: