Created
March 7, 2014 20:48
-
-
Save supritashankar/9419755 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
class Info: | |
def __init__(self, index, name): | |
self.name = name | |
self.index = index | |
def __repr__(self): | |
return repr((self.name, self.index)) | |
inf1 = Info(2, "two") | |
inf2 = Info(1, "one") | |
inf3 = Info(-1, "Minus-one") | |
inf4 = Info(3, "Three") | |
inf5 = Info(0, "Zero") | |
list_of_info = [inf1, inf2, inf3, inf4, inf5] | |
list_sorted = sorted(list_of_info, key=lambda info: info.index) | |
print list_sorted | |
def validate(list_obj): | |
flag = 0 | |
prev = list_obj[0].index | |
for info in list_sorted[1:]: | |
if info.index - prev != 1 and info.index - prev != -1: | |
print 'invalid sequence' | |
return | |
if info.index == 0: | |
flag = 1 | |
prev = info.index | |
print 'sequence is correct' | |
print list_obj | |
validate(list_sorted) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment