Last active
September 21, 2015 18:19
-
-
Save ashishb/65323184ce9daacb3dd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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