Compare Line to Next Line

107 views Asked by At

I have a text file that contains a bunch of items:

One

Two

Three

Three

Four

Five

Five

and I want it to spit out Three and Five since they appeare more than once.

1

There are 1 answers

0
Beri On

In python it would look like this:

lines = {}
with open( "file.txt", "r" ) as src:
  for line in ins.readlines():
      lines[line] = lines.get(line, 0) + 1

for line_key in lines.keys():
   if lines.get(line_key, 0 ) > 0:
      print line_key