root/lib/util.py @ 331
1 | 11 | aaronmk | # Useful functions and classes
|
---|---|---|---|
2 | |||
3 | 135 | aaronmk | def module(value): return type(value).__module__.split('.') |
4 | |||
5 | def root_module(value): return module(value)[0] |
||
6 | |||
7 | def first(iter_): return iter_.next() |
||
8 | |||
9 | 133 | aaronmk | def skip(iter_, func): |
10 | # Advance iter while func is True
|
||
11 | try: |
||
12 | while func(iter_.curr()): iter_.next() |
||
13 | except StopIteration: pass # nothing after the matching elements |
||
14 | |||
15 | 330 | aaronmk | def rename_key(dict_, orig, new): dict_[new] = dict_.pop(orig) |