python - Concatenating list results from multiple functions -


so, i've got few functions return tuples. of form:

def function():     return (thing, other_thing) 

i want able add several of these functions in straightforward way, this:

def use_results(*args):     """     each arg function 1 above     """     results = [test() test in args]     things = magic_function(results)     other_things = magic_function(results) 

basically have data structure:

[([item_1, item_1], [item_2, item_2]), ([item_3, item_3], [item_4, item_4])] 

and want turn into:

[[item_1, item_1, item_3, item_3], [item_2, item_2, item_4, item_4]] 

it seems there's nice pythonic way of doing combination of zip , *, it's not quite coming me.

oh, feel kind of silly. found answer after posting question. i'm going still keep in case there's better solution though:

>>> import operator >>> results = [([1,1], [2,2]), ([3,3], [4,4])] >>> map(operator.add, *results) [[1, 1, 3, 3], [2, 2, 4, 4]] 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -