Created
March 8, 2013 14:43
-
-
Save martync/5116875 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
def get_max_consecutive_number(datas): | |
""" | |
Retourne le nombre maximum de chiffres consécutifs | |
dans une listes. (Y'a t'il un built-in pour ça ? Itertool ?) | |
>> suit = [2003, 2008, 2007, 2001, 2010] | |
>> print get_max_consecutive_number(suit) | |
>>>> 2 | |
>> suit = [2003, 2008, 2007, 2001, 2002, 2004] | |
>> print get_max_consecutive_number(suit) | |
>>>> 4 | |
""" | |
prev_num = None | |
count = 0 | |
counts = [] | |
for d in sorted(list(set(datas))): | |
if prev_num is None: | |
count += 1 | |
else: | |
nexts = (prev_num+1, prev_num-1) | |
if d in nexts: | |
count += 1 | |
else: | |
count = 1 | |
prev_num = d | |
counts.append(count) | |
return sorted(counts, reverse=True)[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment