Skip to content

Instantly share code, notes, and snippets.

@t0ster
Created December 23, 2010 22:32
Show Gist options
  • Save t0ster/753637 to your computer and use it in GitHub Desktop.
Save t0ster/753637 to your computer and use it in GitHub Desktop.
def raskolbas(iterable, r):
"""
>>> raskolbas(['one', 'two', 'three', 'four', 'five'], 2)
[['one', 'two'], ['two', 'three'], ['three', 'four'], ['four', 'five']]
"""
l = list(iterable)
return reduce(lambda x, y: (x.append(x[-1][-r+1:] + [y]), x)[-1], l[r:], [l[:r]])
def zakolbas(iterable):
"""
>>> zakolbas([['one', 'two'], ['two', 'three'], ['three', 'four'], ['four', 'five']])
['one', 'two', 'three', 'four', 'five']
"""
return reduce(lambda x, y: (x.append(y[-1]), x)[-1], iterable[1:], iterable[0])
if __name__ == '__main__':
import doctest
doctest.testmod()
print "Ok."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment