Skip to content

Instantly share code, notes, and snippets.

@ashishb
Last active September 21, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashishb/65323184ce9daacb3dd8 to your computer and use it in GitHub Desktop.
Save ashishb/65323184ce9daacb3dd8 to your computer and use it in GitHub Desktop.
from collections import Counter
FILENAME = 'aspath.txt'
f = open(FILENAME, 'r')
for line in f:
# print 'Line read is ', line
mylist = line.split()
# Coalesce adjacent identical values.
newlist = list()
if len(mylist) > 0:
i = 1
newlist.append(mylist[0])
while i < len(mylist):
if mylist[i - 1] != mylist[i]:
newlist.append(mylist[i])
i += 1
result = [k for k, v in Counter(newlist).items() if v > 1]
if result :
print '%s -> %s' % (line.strip(), result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment