list_utils
trestle.common.list_utils
¤
Trestle List Utils.
Attributes¤
Classes¤
Functions¤
as_dict(dict_or_none)
¤
Convert dict or None object to itself or an empty dict if none.
Source code in trestle/common/list_utils.py
55 56 57 |
|
as_filtered_list(list_or_none, filter_condition)
¤
Convert to list and filter based on the condition.
Source code in trestle/common/list_utils.py
48 49 50 51 52 |
|
as_list(list_or_none)
¤
Convert list or None object to itself or an empty list if none.
Source code in trestle/common/list_utils.py
23 24 25 |
|
comma_colon_sep_to_dict(string_or_none)
¤
Convert optional comma and colon-sep list to dict.
Source code in trestle/common/list_utils.py
34 35 36 37 38 39 40 41 42 43 44 45 |
|
comma_sep_to_list(string_or_none)
¤
Convert optional comma-sep string to list of strings and strip.
Source code in trestle/common/list_utils.py
28 29 30 31 |
|
deep_append(dic, path, value)
¤
Append to list in dict.
Source code in trestle/common/list_utils.py
174 175 176 177 178 179 180 181 182 183 |
|
deep_get(dic, path, default=None)
¤
Get value from deep in dictionary.
Source code in trestle/common/list_utils.py
153 154 155 156 157 158 159 160 161 |
|
deep_set(dic, path, value, pop_if_none=True)
¤
Set value deep in dictionary.
pop_if_none will cause the key to be removed if value is None
Source code in trestle/common/list_utils.py
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
deep_update(dic, path, dic_value)
¤
Update the dict based on path.
Source code in trestle/common/list_utils.py
164 165 166 167 168 169 170 171 |
|
delete_item_from_list(item_list, value, key)
¤
Remove the first matching item if it is present in a list based on the callable key matching the query value.
Source code in trestle/common/list_utils.py
94 95 96 97 98 99 100 |
|
delete_list_from_list(item_list, indices)
¤
Delete a list of items from a list based on indices.
Source code in trestle/common/list_utils.py
125 126 127 128 |
|
get_default(item, default)
¤
Return the default value for the item if it is not set.
Source code in trestle/common/list_utils.py
65 66 67 |
|
get_item_from_list(item_list, value, key, remove=False)
¤
Get first item from list if present based on key matching value with option to remove it from the list.
Source code in trestle/common/list_utils.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
is_ordered_sublist(needle, haystack)
¤
Determine if needle is exactly contained in haystack.
The needle list comprises an ordered list of strings. The haystack list comprises an ordered list of strings that is to be searched. If the strings in the needle appear in the haystack in that exact order then return true, else false.
Examples: needle=['a','b','c'], haystack=['x','y','a','b','c','z'], result = True needle=['a','b','c'], haystack=['x','y','a','b','z','c'], result = False
Source code in trestle/common/list_utils.py
70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
join_key_to_list_dicts(dict1, dict2)
¤
Join two dicts of str to List.
Source code in trestle/common/list_utils.py
85 86 87 88 89 90 91 |
|
merge_dicts(dest, src)
¤
Merge the two dicts with priority to src.
Source code in trestle/common/list_utils.py
131 132 133 |
|
none_if_empty(list_)
¤
Convert to None if empty list.
Source code in trestle/common/list_utils.py
60 61 62 |
|
pop_item_from_list(item_list, value, key)
¤
Pop first matching item from a list if it is present based on the key matching the value.
Source code in trestle/common/list_utils.py
120 121 122 |
|
set_or_pop(dic, key, value)
¤
Set if value is non-empty list or not None otherwise remove.
Source code in trestle/common/list_utils.py
186 187 188 189 190 191 |
|
handler: python