Function short-hands
utilz.shorts
Shorthands for common functions or ops
and maps
with specific params set
aslist(e)
Idempotently convert something to a list.
Source code in utilz/shorts.py
71 72 73 |
|
asstr(e)
Idempotently convert something to a str.
Source code in utilz/shorts.py
76 77 78 |
|
checkall(func, iterme, transparent=False)
Check if all elements are func(elem) == True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
callable
|
function that returns True or False |
required |
iterme |
iterable
|
iterable |
required |
transparent |
bool
|
return iterme instead of result if check passes, useful in pipes; Default False |
False
|
Returns:
Name | Type | Description |
---|---|---|
bool | True or False |
Source code in utilz/shorts.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
|
checkany(func, iterme, transparent=False)
Check if any elements are func(elem) == True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
callable
|
function that returns True or False |
required |
iterme |
iterable
|
iterable |
required |
transparent |
bool
|
return iterme instead of result if check passes, useful in pipes; Default False |
False
|
Returns:
Name | Type | Description |
---|---|---|
bool | True or False |
Source code in utilz/shorts.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
discard(*args, **kwargs)
Alias for filter
with invert=True
Source code in utilz/shorts.py
39 40 41 42 43 |
|
equal(*seqs)
Checks if N args of potentionally different lengths are equal.
Non-iterable args are directly compared with ==
Dataframes and arrays both use np.allclose()
for comparison
Source code in utilz/shorts.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
isempty(iterme)
Check if iterable is empty
Source code in utilz/shorts.py
81 82 83 |
|
keep(*args, **kwargs)
Alias for filter
with invert=False
Source code in utilz/shorts.py
32 33 34 35 36 |
|
seq(*args)
Enumerated list
Source code in utilz/shorts.py
46 47 48 |
|
sort(iterme, **kwargs)
Alias for sorted()
Source code in utilz/shorts.py
26 27 28 29 |
|
transpose(nested_iterable)
Flips the nesting on a nested iterable, e.g. a 3 item iterable containing 2 item iterables becomes a 2 item iterable containing 3 item iterables. Tries to preserve the class of the input otherwise returns a list.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nested_iterable |
Iterable
|
an iterable of iterables |
required |
Returns:
Name | Type | Description |
---|---|---|
iterable | transposed nsted iterable |
Source code in utilz/shorts.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
|