Project

General

Profile

« Previous | Next » 

Revision 1281

util.py: Added list_set() and list_setdefault()

View differences:

lib/util.py
82 82
    try: return list_[idx]
83 83
    except IndexError: return default
84 84

  
85
def list_set(list_, idx, value, default=None):
86
    extra_needed = idx + 1 - len(list_)
87
    if extra_needed > 0: list_ += extra_needed*[default]
88
    list_[idx] = value
89

  
90
def list_setdefault(list_, idx, default=None):
91
    try: return list_[idx]
92
    except IndexError:
93
        list_set(list_, idx, default, default)
94
        return default
95

  
85 96
def list_subset(list_, idxs):
86 97
    subset = []
87 98
    for idx in idxs:

Also available in: Unified diff