Author: | Unknown |
---|---|
Release: | $Id$ |
Date: | December 09, 2013 |
Tags: | Python |
A collection of useful, general purpose iterators.
This code was downloaded from an unknown source.
sample # copies from iterator without replacement.
Stores a temporay copy of the items in iterable. The function has thus a possibly high memory footprint and long pre-processing time to yield the first element.
If sample_size is not given, the iterator returns elements in random order ( see random.shuffle() )
group integers into non-overlapping intervals that are at most distance apart.
>>> list( group_by_distance( (1,1,2,4,5,7) ) )
[(1, 3), (4, 6), (7, 8)]
>>> list( group_by_distance( [] ) )
[]
>>> list( group_by_distance( [3] ) )
[(3, 4)]
>>> list( group_by_distance( [3,2] ) )
Traceback (most recent call last):
...
ValueError: iterable is not sorted: 2 < 3