Created
October 31, 2017 08:44
-
-
Save rgerganov/a86d64115a2723ff016917fb23fc0d41 to your computer and use it in GitHub Desktop.
jay
This file contains hidden or 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
#!/usr/bin/env python | |
def is_bigger(a, b): | |
aa = a.split('.') | |
bb = b.split('.') | |
for x,y in zip(aa, bb): | |
if int(x) > int(y): | |
return True | |
return False | |
def update_list(current, updated): | |
result = [] | |
# update current entries | |
for x in current: | |
start = x['start'] | |
end = x['end'] | |
for y in updated: | |
if start == y['start']: | |
if is_bigger(y['end'], end): | |
end = y['end'] | |
result.append({'start': start, 'end': end}) | |
# add new entires which are not present in 'current' | |
for y in updated: | |
found = False | |
for x in current: | |
if x['start'] == y['start']: | |
found = True | |
break | |
if not found: | |
result.append(y) | |
return result | |
if __name__ == '__main__': | |
print is_bigger('1.1.1.6', '1.1.1.5') | |
print is_bigger('1.1.1.3', '1.1.1.5') | |
print is_bigger('1.1.1.30', '1.1.1.5') | |
print update_list([{'start': '1.1.1.2', 'end': '1.1.1.100'}], | |
[{'start': '1.1.1.2', 'end': '1.1.1.254'}, | |
{'start': '1.2.1.2', 'end': '1.2.1.254'}]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment