I am new to python, I need help with how can I get the returning values from a function call. I tried doing this which is apparently wrong I need to assign the returning values to the mentioned variables and I cant make changes on how I return the values from the function as that is what is needed in the question.
((cross_low,cross_high),cross_sum)=find_maximum_crossing_subarray(A,low,mid,high)
I am returning this type of value from the find_maximum_crossing_subarray
function:
tup=(max_left,max_right)
tup1=(tup,left_sum+right_sum)
return tup1
只需删除外面的括号:
(cross_low, cross_high), cross_sum = find_maximum_crossing_subarray(A,low,mid,high)
That's really strange syntax, but basically you're being shown the return signature from find_maximum_crossing_subarray(..)
.
You can see a simplified version,
def some_function():
return (1, 2), 3
x = ((a, b), c) = some_function()
print(x, a, b, c)
...
... output:
((1, 2), 3) 1 2 3
Notice how I still had access to a
, b
, and c
. Similarly, you will have access to your cross_*
variables.
If you need to find the max of something, max
is a built-in function, and so is sum
.
If you can change the return signature of find_maximum_crossing_subarray(..)
I would do this instead:
# ..
return max_left, max_right, left_sum + right_sum
results = find_maximum(A, low, mid, high)
cross_low, cross_high, cross_sum = results
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.