Project

General

Profile

« Previous | Next » 

Revision 1414

util.py: Added list_set_length(). Changed list_set() to use list_set_length().

View differences:

util.py
87 87
    try: return list_[idx]
88 88
    except IndexError: return default
89 89

  
90
def list_set_length(list_, len_, fill=None, expand_only=False):
91
    extra_needed = len_ - len(list_)
92
    if extra_needed > 0: list_ += extra_needed*[fill]
93
    elif not expand_only: del list_[len_:]
94

  
90 95
def list_set(list_, idx, value, default=None):
91
    extra_needed = idx + 1 - len(list_)
92
    if extra_needed > 0: list_ += extra_needed*[default]
96
    list_set_length(list_, idx+1, default, expand_only=True)
93 97
    list_[idx] = value
94 98

  
95 99
def list_setdefault(list_, idx, default=None):

Also available in: Unified diff