Partition a list into equally sized pieces, including last smaller parts
    http://stackoverflow.com/questions/5129102/python-equivalent-to-clojures-partition-all
2551
def partition_all(n, iterable):
    
    it = iter(iterable)
    while True:
        chunk = list(itertools.islice(it, n))
        if not chunk:
            break
        yield chunk
760622
def chunks(lista, size):
    """"""
    if not isinstance(lista, list):
        logger.error('Erron in chunks, arg introduced is not a list.', lista=lista)
        return lista

    for i in range(0, len(lista), size):
        yield lista[i:i + size]
1013102
def _ConstructPartitions(self, collection_links, partitions_per_node):
        
        collections_node_count = len(collection_links)
        partitions = [partition._Partition() for _ in xrange(0, partitions_per_node * collections_node_count)]

        index = 0
        for collection_node in collection_links:
            hash_value = self.hash_generator.ComputeHash(self._GetBytes(collection_node))
            for _ in xrange(0, partitions_per_node):
                partitions[index] = partition._Partition(hash_value, collection_node)
                index += 1
                hash_value = self.hash_generator.ComputeHash(hash_value)

        partitions.sort()
        return partitions
1165467
def _build_full_partition(
        optional_parts, sequence_var_partition: Sequence[int], subjects: Sequence[Expression], operation: Operation
) -> List[Sequence[Expression]]:
    
    i = 0
    var_index = 0
    opt_index = 0
    result = []
    for operand in op_iter(operation):
        wrap_associative = False
        if isinstance(operand, Wildcard):
            count = operand.min_count if operand.optional is None else 0
            if not operand.fixed_size or isinstance(operation, AssociativeOperation):
                count += sequence_var_partition[var_index]
                var_index += 1
                wrap_associative = operand.fixed_size and operand.min_count
            elif operand.optional is not None:
                count = optional_parts[opt_index]
                opt_index += 1
        else:
            count = 1

        operand_expressions = list(op_iter(subjects))[i:i + count]
        i += count

        if wrap_associative and len(operand_expressions) > wrap_associative:
            fixed = wrap_associative - 1
            operand_expressions = tuple(operand_expressions[:fixed]) + (
                create_operation_expression(operation, operand_expressions[fixed:]),
            )

        result.append(operand_expressions)

    return result
981459
def chunk_list(items, size):
    
    size = max(1, size)
    return [items[i:i + size] for i in range(0, len(items), size)]
987101
def trivial_partition(set_):
    
    ensure_countable(set_)

    result = ((x,) for x in set_)
    return _harmonize_subset_types(set_, result)
614646
def slice(l,num_slices=None,slice_length=None,runts=True,random=False):
	
	if random:
		import random
		random.shuffle(l)
	if not num_slices and not slice_length: return l
	if not slice_length: slice_length=int(len(l)/num_slices)
	newlist=[l[i:i+slice_length] for i in range(0, len(l), slice_length)]
	if runts: return newlist
	return [lx for lx in newlist if len(lx)==slice_length]
922811
def full(self):
        
        return self.maxsize and len(self.list) >= self.maxsize or False
1035762
private static <T extends Comparable<T>> List<Interval<T>> combine(Partition<T> p1, Partition<T> p2) throws MIDDException {

        Set<EndPoint<T>> boundSet = new HashSet<EndPoint<T>>();

        //collect all bounds and remove duplicated items
        for (Interval<T> interval : p1.getIntervals()) {
            boundSet.add(interval.getLowerBound());
            boundSet.add(interval.getUpperBound());
        }
        for (Interval<T> interval : p2.getIntervals()) {
            boundSet.add(interval.getLowerBound());
            boundSet.add(interval.getUpperBound());
        }

        //sorting the bounds
        List<EndPoint<T>> sortedBounds = new ArrayList<EndPoint<T>>(boundSet);
        Collections.sort(sortedBounds);

        List<Interval<T>> tempPartition = new ArrayList<Interval<T>>();

        // Generate new intervals
        for (int i = 0; i < sortedBounds.size() - 1; i++) {
            EndPoint<T> lowBound = sortedBounds.get(i);
            EndPoint<T> upBound = sortedBounds.get(i + 1);
            tempPartition.add(new Interval<T>(lowBound));
            tempPartition.add(new Interval<T>(lowBound, upBound));
        }
        // add the last end-point
        if (sortedBounds.size() > 0) {
            EndPoint<T> lastBound = sortedBounds.get(sortedBounds.size() - 1);
            tempPartition.add(new Interval<T>(lastBound));
        } else {
            log.warn("empty sortedBound");

        }
        return tempPartition;
    }
311495
def split(examples, ratio=0.8):
        
        split = int(ratio * len(examples))
        return examples[:split], examples[split:]
606711
def partition_by(num_partitions, partition_func=nil)
      num_partitions ||= default_reduce_partitions
      partition_func ||= 'lambda{|x| Spark::Digest.portable_hash(x.to_s)}'

      _partition_by(num_partitions, Spark::Command::PartitionBy::Basic, partition_func)
    end
160844
def _chunk(iterable, size):
    """"""
    # We're going to use some star magic to chunk the iterable. We create a
    # copy of the iterator size times, then pull a value from each to form a
    # chunk. The last chunk may have some trailing Nones if the length of the
    # iterable isn't a multiple of size, so we filter them out.

    args = (iter(iterable),) * size

    return (
        # pylint: disable=star-args
        itertools.takewhile(lambda x: x is not None, group)
        for group in itertools.zip_longest(*args)
    )
1057838
def sort_and_distribute(array, splits=2):
   
   if not isinstance(array, (list,tuple)): raise TypeError("array must be a list")
   if not isinstance(splits, int): raise TypeError("splits must be an integer")
   remaining = sorted(array)
   if sys.version_info < (3, 0):
      myrange = xrange(splits)
   else:
      myrange = range(splits)
   groups = [[] for i in myrange]
   while len(remaining) > 0:
      for i in myrange:
         if len(remaining) > 0: groups[i].append(remaining.pop(0))
   return groups
1049279
def _partition(hours, partition = 3600.0):
		
		partition = float(partition)
		relative = hours - hours[0]
		total_partitions = np.ceil(relative[-1] / partition + 10*np.finfo(np.float).eps).astype('int')
		return [hours[np.floor(np.divide(relative, partition)) == i] for i in range(total_partitions)]
1133682
def splits(self):
        
        return list(map(lambda x: self.select_code(x), self.code))
409413
def k_partitions(collection, k):
    
    collection = list(collection)
    n = len(collection)

    # Special cases
    if n == 0 or k < 1:
        return []
    if k == 1:
        return [[collection]]

    a = [0] * (n + 1)
    for j in range(1, k + 1):
        a[n - k + j] = j - 1
    return _f(k, n, 0, n, a, k, collection)
989822
def mapPartitions(self, f, preservesPartitioning=False):
        
        def func(s, iterator):
            return f(iterator)
        return self.mapPartitionsWithIndex(func, preservesPartitioning)