iterative
Functions for iteration, looping etc.
New in version 1.4.0.
Data:
Functions:
|
Shorthand for |
|
Yield successive |
|
Make an iterator which returns evenly spaced values starting with number |
|
Flatten a list of lists of lists into a single list. |
|
Extend |
|
Extend |
|
Extend |
|
Flattens a mixed list of primitive types and iterables of those types into a single list, regardless of nesting. |
|
Returns an iterator over the discrete ranges of values in |
|
Returns the string representation of a mixed list of strings and lists of strings, similar to tree(1). |
|
Returns the maximum value from |
|
Returns the minimum value from |
|
Return permutations containing |
|
Returns an iterator over the minimum and maximum values for each discrete ranges of values in |
|
Split |
-
Len
(obj, start=0, step=1)[source] Shorthand for
range(len(obj))
.Returns an object that produces a sequence of integers from
start
(inclusive) tolen(obj)
(exclusive) bystep
.New in version 0.4.7.
- Parameters
- Return type
Changed in version 1.4.0: Moved from
domdf_python_tools.utils
-
chunks
(l, n)[source] Yield successive
n
-sized chunks froml
.- Parameters
- Return type
Changed in version 1.4.0: Moved from
domdf_python_tools.utils
-
count
(start=0, step=1)[source] Make an iterator which returns evenly spaced values starting with number
start
.Often used as an argument to
map()
to generate consecutive data points. Can also be used withzip()
to add sequence numbers.New in version 2.7.0.
- Parameters
- Return type
See also
The difference is that this returns more exact floats, whereas the values from
itertools.count()
drift.A demonstration of the drift can be seen in this file:
count_demo.py
.
-
double_chain
(iterable)[source] Flatten a list of lists of lists into a single list.
Literally just:
chain.from_iterable(chain.from_iterable(iterable))
Will convert
[[(1, 2), (3, 4)], [(5, 6), (7, 8)]]
to
[1, 2, 3, 4, 5, 6, 7, 8]
New in version 0.4.7.
- Parameters
iterable (
Iterable
[Iterable
[Iterable
[~_T
]]]) – The iterable to chain.- Return type
Iterator
[~_T
]
Changed in version 1.4.0: Moved from
domdf_python_tools.utils
-
extend
(sequence, minsize)[source] Extend
sequence
by repetition until it is at least as long asminsize
.New in version 2.3.0.
See also
-
extend_with
(sequence, minsize, with_)[source] Extend
sequence
by addingwith\_
to the right hand end until it is at least as long asminsize
.New in version 2.3.0.
See also
-
extend_with_none
(sequence, minsize)[source] Extend
sequence
by addingNone
to the right hand end until it is at least as long asminsize
.New in version 2.3.0.
See also
-
flatten
(iterable, primitives=(<class 'str'>, <class 'int'>, <class 'float'>))[source] Flattens a mixed list of primitive types and iterables of those types into a single list, regardless of nesting.
New in version 1.4.0.
-
groupfloats
(iterable, step=1)[source] Returns an iterator over the discrete ranges of values in
iterable
.For example:
>>> list(groupfloats( ... [170.0, 170.05, 170.1, 170.15, 171.05, 171.1, 171.15, 171.2], ... step=0.05, ... )) [(170.0, 170.05, 170.1, 170.15), (171.05, 171.1, 171.15, 171.2)] >>> list(groupfloats([1, 2, 3, 4, 5, 7, 8, 9, 10])) [(1, 2, 3, 4, 5), (7, 8, 9, 10)]
New in version 2.0.0.
- Parameters
- Return type
See also
ranges_from_iterable()
, which returns an iterator over the min and max values for each range.
-
make_tree
(tree)[source] Returns the string representation of a mixed list of strings and lists of strings, similar to tree(1).
New in version 1.4.0.
-
natmax
(seq, key=None, alg=<ns.DEFAULT: 0>)[source] Returns the maximum value from
seq
when sorted naturally.New in version 1.8.0.
- Parameters
seq (
Iterable
[~_T
])key (
Optional
[Callable
[[Any
],Any
]]) – A key used to determine how to sort each element of the iterable. It is not applied recursively. The callable should accept a single argument and return a single value. DefaultNone
.alg (
int
) – This option is used to control which algorithmnatsort
uses when sorting. Default<ns.DEFAULT: 0>
.
- Return type
~_T
-
natmin
(seq, key=None, alg=<ns.DEFAULT: 0>)[source] Returns the minimum value from
seq
when sorted naturally.New in version 1.8.0.
- Parameters
seq (
Iterable
[~_T
])key (
Optional
[Callable
[[Any
],Any
]]) – A key used to determine how to sort each element of the iterable. It is not applied recursively. The callable should accept a single argument and return a single value. DefaultNone
.alg (
int
) – This option is used to control which algorithmnatsort
uses when sorting. Default<ns.DEFAULT: 0>
.
- Return type
~_T
-
permutations
(data, n=2)[source] Return permutations containing
n
items fromdata
without any reverse duplicates.If
n
is equal to or greater than the length of the data an empty list of returned.Changed in version 1.4.0: Moved from
domdf_python_tools.utils
See also
-
ranges_from_iterable
(iterable, step=1)[source] Returns an iterator over the minimum and maximum values for each discrete ranges of values in
iterable
.For example:
>>> list(ranges_from_iterable([170.0, 170.05, 170.1, 170.15, 171.05, 171.1, 171.15, 171.2], step=0.05)) [(170.0, 170.15), (171.05, 171.2)] >>> list(ranges_from_iterable([1, 2, 3, 4, 5, 7, 8, 9, 10])) [(1, 5), (7, 10)]