Project

General

Profile

« Previous | Next » 

Revision 1344

util.py: Added list_replace()

View differences:

lib/util.py
107 107
        if list0[i] is not list1[i]: return False
108 108
    return True
109 109

  
110
def list_replace(list_, repl_elem, with_slice):
111
    list_ = list_[:] # don't modify input!
112
    while True:
113
        try: idx = list_.index(repl_elem)
114
        except ValueError: break
115
        list_[idx:idx+1] = with_slice
116
    return list_
117

  
110 118
def list_flip(list_): return dict((v, i) for i, v in enumerate(list_))
111 119

  
112 120
#### Dicts

Also available in: Unified diff