返回Iterable中最小的N个对象, back by guava.
191713
public static <T extends Comparable<?>> List<T> bottomN(Iterable<T> coll, int n) {
		return Ordering.natural().leastOf(coll, n);
	}
548369
def chunk(iterable, chunk_size=20):
    """"""
    items = []
    for value in iterable:
        items.append(value)
        if len(items) == chunk_size:
            yield items
            items = []
    if items:
        yield items
951970
def ngram(n, iter_tokens):
    
    z = len(iter_tokens)
    return (iter_tokens[i:i+n] for i in range(z-n+1))
948032
def min_count(self, n=1):
    
    word_count = {w:c for w,c in iteritems(self.word_count) if c >= n}
    return CountedVocabulary(word_count=word_count)
703701
def _pairwise(iterable):
    
    a, b = itertools.tee(iterable)
    next(b, None)
    return zip(a, b)
766034
public static <T> Iterable<T> simpleIterable(final Iterable<T> iterable) {
        requireNonNull(iterable);
        return () -> iterable.iterator();
    }
372960
def itertypes(iterable):
    """"""
    seen = set()
    for entry in iterable:
        if isinstance(entry, tuple):
            for type_ in entry:
                if type_ not in seen:
                    seen.add(type_)
                    yield type_
        else:
            if entry not in seen:
                seen.add(entry)
                yield entry
911678
def batch(iterable, chunk_size):
    
    i = iter(iterable)
    while True:
        r = list(itertools.islice(i, chunk_size))
        if not r:
            break
        yield r
479927
def pairwise(iterable):
    ""
    now, nxt = tee(iterable)
    next(nxt, None)
    return izip(now, nxt)
961002
def split_seq(iterable, size):
    """"""
    elm = iter(iterable)
    item = list(itertools.islice(elm, size))
    while item:
        yield item
        item = list(itertools.islice(elm, size))
945482
def pairwise(iterable):
    
    iterable = iter(iterable)
    left = next(iterable)
    for right in iterable:
        yield left, right
        left = right
95471
def kth_smallest(self, root, k):
        
        count = []
        self.helper(root, count)
        return count[k-1]
170209
def maximal(iterable, comparison=operator.lt, _groupkey=operator.itemgetter(0)):
    
    iterable = set(iterable)
    if len(iterable) < 2:
        return iterable
    return (item for item, pairs
        in groupby(permutations(iterable, 2), key=_groupkey)
        if not any(starmap(comparison, pairs)))
803883
def chunk(self, iterable, n, fillvalue=None):
    ""
    # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx
    args = [iter(iterable)] * n
    return izip_longest(fillvalue=fillvalue, *args)
668151
def popwhile(predicate, iterable):
    
    while iterable:
        item = iterable.pop()
        if predicate(item):
            yield item
        else:
            break
327050
def grouper(iterable, n):
    ''''''
    args = [iter(iterable)] * n
    for group in izip_longest(fillvalue=None, *args):
        group = [g for g in group if g != None]
        yield group
789874
def len(iterable):
    
    if not isinstance(iterable, str):
        return iterable.__len__()

    try:
        return len(unicode(iterable, 'utf'))
    except:
        return iterable.__len__()