Last active
December 5, 2018 14:15
-
-
Save VerosK/9e071f2a7c18c4a9970f59580bc7211f to your computer and use it in GitHub Desktop.
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
from __future__ import print_function | |
from random import randint | |
def random_address(): | |
retv = [str(randint(1,255)) for i in 'abcd'] | |
return '.'.join(retv) | |
addresses = [random_address() for i in range(15)] | |
def sort_key(k): | |
parts = k.split('.') | |
retv = [int(i) for i in parts] | |
print('k={}, parts={}\nretv={}\n'. | |
format(k, parts, retv)) | |
return retv | |
addresses.sort(key=sort_key) | |
print(addresses) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment