Skip to content

Instantly share code, notes, and snippets.

@rgerganov
Created October 31, 2017 08:44
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 rgerganov/a86d64115a2723ff016917fb23fc0d41 to your computer and use it in GitHub Desktop.
Save rgerganov/a86d64115a2723ff016917fb23fc0d41 to your computer and use it in GitHub Desktop.
jay
#!/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