text
stringlengths 0
828
|
---|
else: |
return join_impl(left, right, lkey, rkey, join_fn)" |
4754,"def _inner_join(left, right, left_key_fn, right_key_fn, join_fn=union_join): |
"""""" Inner join using left and right key functions |
:param left: left iterable to be joined |
:param right: right iterable to be joined |
:param function left_key_fn: function that produces hashable value from left objects |
:param function right_key_fn: function that produces hashable value from right objects |
:param join_fn: function called on joined left and right iterable items to complete join |
:rtype: list |
"""""" |
joiner = defaultdict(list) |
for ele in right: |
joiner[right_key_fn(ele)].append(ele) |
joined = [] |
for ele in left: |
for other in joiner[left_key_fn(ele)]: |
joined.append(join_fn(ele, other)) |
return joined" |
4755,"def _right_join(left, right, left_key_fn, right_key_fn, join_fn=union_join): |
"""""" |
:param left: left iterable to be joined |
:param right: right iterable to be joined |
:param function left_key_fn: function that produces hashable value from left objects |
:param function right_key_fn: function that produces hashable value from right objects |
:param join_fn: function called on joined left and right iterable items to complete join |
:rtype: list |
"""""" |
def reversed_join_fn(left_ele, right_ele): |
return join_fn(right_ele, left_ele) |
return _left_join(right, left, right_key_fn, left_key_fn, reversed_join_fn)" |
4756,"def _outer_join(left, right, left_key_fn, right_key_fn, join_fn=union_join): |
"""""" |
:param left: left iterable to be joined |
:param right: right iterable to be joined |
:param function left_key_fn: function that produces hashable value from left objects |
:param function right_key_fn: function that produces hashable value from right objects |
:param join_fn: function called on joined left and right iterable items to complete join |
:rtype: list |
"""""" |
left_joiner = defaultdict(list) |
for ele in left: |
left_joiner[left_key_fn(ele)].append(ele) |
right_joiner = defaultdict(list) |
for ele in right: |
right_joiner[right_key_fn(ele)].append(ele) |
keys = set(left_joiner.keys()).union(set(right_joiner.keys())) |
def iter_join(l, r, join_keys): |
for join_key in join_keys: |
for ele in l.get(join_key, [None]): |
for other in r.get(join_key, [None]): |
yield join_fn(ele, other) |
return list(iter_join(left_joiner, right_joiner, keys))" |
4757,"def group(iterable, key=lambda ele: ele): |
"""""" Groups an iterable by a specified attribute, or using a specified key access function. Returns tuples of grouped elements. |
>>> dogs = [Dog('gatsby', 'Rruff!', 15), Dog('william', 'roof', 12), Dog('edward', 'hi', 15)] |
>>> groupby(dogs, 'weight') |
[(Dog('gatsby', 'Rruff!', 15), Dog('edward', 'hi', 15)), (Dog('william', 'roof', 12), )] |
:param iterable: iterable to be grouped |
:param key: a key-access function or attr name to be used as a group key |
"""""" |
if callable(key): |
return _group(iterable, key) |
else: |
return _group(iterable, make_key_fn(key))" |
4758,"def trigger_keyphrases( |
text = None, # input text to parse |
keyphrases = None, # keyphrases for parsing input text |
response = None, # optional text response on trigger |
function = None, # optional function on trigger |
kwargs = None, # optional function keyword arguments |
confirm = False, # optional return of confirmation |
confirmation_prompt = ""Do you want to continue? (y/n)"", |
confirmation_feedback_confirm = ""confirm"", |
confirmation_feedback_deny = ""deny"" |
): |
"""""" |
Parse input text for keyphrases. If any keyphrases are found, respond with |
text or by seeking confirmation or by engaging a function with optional |
keyword arguments. Return text or True if triggered and return False if not |
triggered. If confirmation is required, a confirmation object is returned, |
encapsulating a function and its optional arguments. |
"""""" |
if any(pattern in text for pattern in keyphrases): |
if confirm: |
return confirmation( |
prompt = confirmation_prompt, |
feedback_confirm = confirmation_feedback_confirm, |
feedback_deny = confirmation_feedback_deny, |
function = function, |
kwargs = kwargs |
) |
if function and not kwargs: |
result = function() |
elif function and kwargs: |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.