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
Post a Comment