Project

General

Profile

« Previous | Next » 

Revision 1767

util.py: Added sort_by_len(), shortest(), longest()

View differences:

lib/util.py
143 143

  
144 144
def list_flip(list_): return dict((v, i) for i, v in enumerate(list_))
145 145

  
146
def sort_by_len(list_of_lists): list_of_lists.sort(lambda *a: cmp(*map(len, a)))
147

  
148
def shortest(*lists):
149
    lists = list(lists)
150
    sort_by_len(lists)
151
    return lists[0]
152

  
153
def longest(*lists):
154
    lists = list(lists)
155
    sort_by_len(lists)
156
    return lists[-1]
157

  
146 158
#### Dicts
147 159

  
148 160
def rename_key(dict_, orig, new): dict_[new] = dict_.pop(orig)

Also available in: Unified diff