Reputation: 213
So I have little problem. I have 2 locations and sports day results:
location1 = [401, 604, 547, 700, 722, 845, 621, 490, 800, 700]
location2 = [900, 0, 333, 803, 838, 400, 467, 488, 432, 700]
and I have to get results that way, that only the best is shown. Also in the end there have to be sum of these results. Final result should look like this:
[900, 604, 547, 803, 845, 621, 490, 800, 700]
Sum: 7148
All I get is location with best overall score and sum, not the best results from each. Anyone have ideas?
Upvotes: 1
Views: 64
Reputation: 3806
This will also work.
best_results = list(map(lambda x: max(location1[x], location2[x]), range(len(location1))))
total = sum(best_results)
Upvotes: 1
Reputation: 27
results = [max(x,y) for x,y in zip(location1, location2)]
total = sum(results)
Upvotes: 0
Reputation: 1168
Try this:
max_results = [max(item) for item in zip(location1,location2)]
total = sum(max_results)
Or just for sport:
max_results = [max(location1[index],location2[index]) for index in range(0, len(location1))]
Upvotes: 2