List¶
An ordered collection of elements
Details Tips:
- Lists can be efficiently used as a stack through
append()(for push) andpop(). - Sorting seems to be broken for numeric lists containing NaN
Create list¶
| Action | Code | Details |
|---|---|---|
| Empty list |
|
|
| List with single element |
|
|
| Define with values |
|
|
| Define with n repeated values v |
|
|
| List of n increasing counts, starting from zero |
|
|
| List of increasing counts, starting from zero with step size s |
|
|
| List of n decreasing counts to zero |
|
|
| List of n decreasing counts to zero, with step size s |
|
|
| List of increasing integers between [a, b] |
|
|
| From tuple |
|
|
| From iterable |
|
Fully consumes the iterable. |
| Lists from zipped list |
|
|
| Sample n random integers between [ a, b ) with replacement |
|
Considerably faster than list comprehension |
| Sample n random integers between [ a, b ) w/o replacement |
|
|
| From lists generated dynamically by iterating over a generating function fun |
|
|
| Generate list of r-length permutation tuples from indices up to b |
|
Returns [(0, 0), (0, 1), ..., (b - 1, b - 1)] |
Test¶
| Action | Code | Details |
|---|---|---|
| Is list or subclass |
|
|
| Is list and not subclass |
|
|
| Empty |
|
|
| Not empty |
|
|
| Pairwise equal to another list |
|
|
Contains None
|
|
|
| Contains element e |
|
|
| Contains elements |
|
|
| Contains elements elems |
|
|
| Does not contain element e |
|
|
| Elements are all of type t |
|
e.g., type str |
| All elements True |
|
|
| Any element True |
|
|
| Are elements sorted |
|
|
| No duplicate elements |
|
|
| Has duplicate elements |
|
extract¶
| Action | Code | Details |
|---|---|---|
| Number of elements (length) |
|
|
| Hash |
|
|
| First element |
|
|
| Last element |
|
|
| Random element |
|
|
| Number of occurrences of element |
|
|
| Index of element |
|
Throws error if not found |
| Index of element in slice [a,b] |
|
Throws error if not found |
Aggregate¶
| Action | Code | Details |
|---|---|---|
| Min |
|
|
| Max |
|
|
| Sum |
|
|
| Mean |
|
Faster than fmean and mean from statistics |
| Most frequent element (mode) |
|
Update¶
Transform¶
| Action | Code | Details |
|---|---|---|
| Update element at index i |
|
|
| Update slice with list |
|
Order¶
| Action | Code | Details |
|---|---|---|
| Reverse elements |
|
|
| Sort elements ascending |
|
|
| Sort elements descending |
|
|
| Sort on transformed elements, ascending |
|
Grow¶
| Action | Code | Details |
|---|---|---|
| Append element |
|
|
| Append a list |
|
|
| Append a list |
|
|
| Insert at index i |
|
Shrink¶
| Action | Code | Details |
|---|---|---|
| Clear |
|
|
| Clear |
|
Probably slower |
| Remove at index i |
|
|
| Remove at index i |
|
|
| Remove slice |
|
|
| Remove slice |
|
|
| Remove element (first occurrence) |
|
|
| Remove all elements with value |
|
|
| Remove last index and return the element (pop) |
|
|
| Remove at index i and return the element |
|
Derive¶
| Action | Code | Details |
|---|---|---|
| Shallow copy |
|
Fastest for large lists |
| Shallow copy |
|
Fastest for small lists |
| Shallow copy |
|
Probably very slow |
| Shallow copy |
|
Not sure what the difference to .copy() is |
| Deep copy (don't preserve refs) |
|
Constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original. |
Transform¶
| Action | Code | Details |
|---|---|---|
| Transform via expression |
|
|
| Map function |
|
|
| Map function |
|
Slow |
| Elements to string |
|
|
| Conditional update |
|
|
| Ternary map |
|
|
| Nested ternary map |
|
Good luck reading this |
| Rank ascendingly |
|
Uses scipy package |
| Sort-index ascendingly |
|
Uses numpy package |
| Sort-index ascendingly |
|
|
| Sort-index ascendingly |
|
Tedious |
Order¶
| Action | Code | Details |
|---|---|---|
| Reverse |
|
|
| Sort ascendingly |
|
Elements must be sortable! |
| Sort descendingly |
|
Elements must be sortable! |
| Sort by reference order list |
|
|
| Naturally sort string elements |
|
E.g., sort as ['abc1', 'abc2', 'abc10'] |
| Shuffle elements |
|
Grow¶
| Action | Code | Details |
|---|---|---|
| Replicate list n times |
|
|
| Replicate to ensure length n |
|
|
| Append element |
|
|
| Append elements |
|
|
| Append a list |
|
Shrink¶
| Action | Code | Details |
|---|---|---|
| Slice |
|
|
| First n elements (head) |
|
|
| Last n elements (tail) |
|
|
| Select n elements at random |
|
|
| Remove first n elements |
|
|
| Remove last n elements |
|
|
| List of elements from a list of indices |
|
|
| Filter on condition |
|
|
| Filter on predicate function |
|
Combine lists¶
| Action | Code | Details |
|---|---|---|
| Concatenate lists |
|
Iterate¶
Iterate over the elements of the list
| Action | Code | Details |
|---|---|---|
| Loop over elements |
|
|
| Loop over elements and index |
|
|
| Loop over elements and index, starting from index s |
|
|
| Loop over multiple lists |
|
|
| Loop over multiple lists, with index |
|
|
| Iterate over a list of lists for each nested element |
|
Convert¶
| Action | Code | Details |
|---|---|---|
| Multiple assignment |
|
|
| Tuple |
|
|
| Set |
|
|
| To dict (from keys and values) |
|
|
| Flatten a list of lists |
|