one to many (passing variables)
Steven D'Aprano
steve at pearwood.info
Thu Jul 24 05:15:50 EDT 2014
On Thu, 24 Jul 2014 09:27:10 +0200, Martin S wrote:
> Function A collects data and then calls function B with some, but also
> has data that should be passed to function C.
It might help if you give a bit more information. How does it collect
data, how does it decide which bits of information should be passed to B
and which to C, and what happens with the results returned from B and C?
But something like this should give you an idea:
def funca(values):
data_for_b = []
data_for_c = []
for value in values:
if 0 < value <= 100:
data_for_b.append(value)
elif 100 < value <= 200:
data_for_c.append(value)
# otherwise just discard it
result_from_b = funcb(data_for_b)
result_from_a = funcc(data_for_c)
return max(result_from_b, result_from_a)
def funcb(values):
return 5*sum(values)
def funcc(values):
return 2*sum(values) - 200
print(funca([2, 5, 107, 99, 1999, 2345, 84, 156, 23]))
If you run that code, it should print 1065.
If this is not what you mean, I'm afraid you're going to have to explain
what exactly you do mean, because I have no other ideas :-)
--
Steven
More information about the Python-list
mailing list