Created
October 4, 2012 13:34
-
-
Save OddBloke/3833554 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For extracting user and pass | |
preds = map(eq_fact, ['user_name', 'password']) | |
[[user_name], [password]] = pred_list_partition(preds, kwargs, False) | |
def eq_fact(name): | |
def wrapped(x): | |
return x == name | |
return wrapped | |
def pred_list_partition(predicate_list, in_list, with_else=True): | |
""" | |
Partitions the list based on predicate_list. | |
This creates len(predicate_list) lists or +1 if with_else is True | |
and inserts each element of in_list to the list of the first predicate | |
that returns true or to the last one if with else is True otherwise drops | |
the element | |
""" | |
if with_else: | |
predicate_list.append(lambda x: True) | |
pcount = len(predicate_list) | |
ret = [[] for _ in xrange(pcount)] | |
for el in in_list: | |
for i in xrange(pcount): | |
if predicate_list[i](el): | |
ret[i].append(el) | |
break | |
return ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment