Created
February 6, 2013 16:12
-
-
Save rizsotto/4723645 to your computer and use it in GitHub Desktop.
first python code from me
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
def _extend_list(numbers, size): | |
copy = numbers[:] | |
current_size = len(copy) | |
for i in range(current_size, size): | |
copy.append(0) | |
return copy | |
class Version: | |
def __init__(self, string): | |
tokens = string.split('.') | |
self.numbers = [int(t) for t in tokens] | |
def __str__(self): | |
return '.'.join([str(i) for i in self.numbers]) | |
def __repr__(self): | |
return self.__str__() | |
def __cmp__(self, other): | |
lhs = _extend_list(self.numbers, len(other.numbers)) | |
rhs = _extend_list(other.numbers, len(self.numbers)) | |
for l,r in zip(lhs, rhs): | |
if l > r: | |
return 1 | |
elif r < l: | |
return -1 | |
return 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment