pysnippets.lists
Splitting, grouping, de-duplicating and comparing sequences.
- bifurcate_by(items, predicate)Partition items into those that pass a test and those that don't, in one pass.
- chunk_into_n(items, n)Split a sequence into exactly n lists whose sizes differ by at most one.
- count_by(items, key)Count how many items map to each key, using collections.Counter.
- deep_flatten(items)Lazily yield every value from arbitrarily nested iterables, treating strings as values.
- difference_by(a, b, key)Keep the items of one list whose key doesn't appear in another, preserving order.
- duplicates(items) +1List the values that repeat, or the ones that appear exactly once.
- every_nth(items, n)Take every nth item from a sequence, starting with the nth, using a slice.
- group_by(items, key)Bucket items into lists keyed by a function, keeping the original order inside each group.
- has_duplicates(items)Return True as soon as any value repeats, even in a huge or endless iterable.
- have_same_contents(a, b)Compare two collections regardless of order, counting duplicates, in linear time.
- index_of_all(items, value) +1Return all positions of a value, or of items matching a predicate.
- intersection_by(a, b, key)Keep the items of one list whose key also appears in another, preserving order.
- most_frequent(items)Return the most common item, breaking ties by first appearance.
- sort_by_indexes(items, indexes, *, reverse)Order items by the number at the same position in a second list.
- union_by(a, b, key)Merge two lists, keeping the first item for each key, in a predictable order.
- unique_elements(items)De-duplicate a list while keeping the first occurrence of each value, in order.