Revision 2020
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/util.py | ||
---|---|---|
117 | 117 |
list_set(list_, idx, default, default) |
118 | 118 |
return default |
119 | 119 |
|
120 |
def list_subset(list_, idxs): |
|
121 |
'''@param idxs list|None If None, returns entire list''' |
|
120 |
subset_skip = object() # tells list_subset() to leave out invalid indexes |
|
121 |
|
|
122 |
def list_subset(list_, idxs, default=subset_skip): |
|
123 |
''' |
|
124 |
@param idxs list|None If None, returns entire list |
|
125 |
@param default The value to use for invalid indexes, or subset_skip to leave |
|
126 |
them out of the returned list |
|
127 |
''' |
|
122 | 128 |
if idxs == None: return list_ |
123 | 129 |
subset = [] |
124 | 130 |
for idx in idxs: |
125 |
try: subset.append(list_[idx])
|
|
126 |
except IndexError: pass
|
|
131 |
value = list_get(list_, idx, default)
|
|
132 |
if value != subset_skip: subset.append(value)
|
|
127 | 133 |
return subset |
128 | 134 |
|
129 | 135 |
def list_eq_is(list0, list1): |
Also available in: Unified diff
util.py: list_subset(): Added default param to specify the value to use for invalid indexes (if any)