def pairwise(iterable): "s -> (s0,s1), (s1,s2), (s2, s3), ..." a, b = tee(iterable) next(b, None) return zip(a, b)
def bouncy_pairwise(number): """ tests whether a number is bouncy """ digits = str(number) increasing = decreasing = False for a, b in pairwise(digits): if not increasing and a > b: increasing = True if not decreasing and a < b: decreasing = True if increasing and decreasing: return True
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = tee(iterable)
next(b, None)
return zip(a, b)
def bouncy_pairwise(number):
"""
tests whether a number is bouncy
"""
digits = str(number)
increasing = decreasing = False
for a, b in pairwise(digits):
if not increasing and a > b:
increasing = True
if not decreasing and a < b:
decreasing = True
if increasing and decreasing:
return True