[Ilugc] [PYTHON] sum of best two scores of three

  • From: vkslist@xxxxxxxxx (Sameer)
  • Date: Sat, 31 Dec 2011 10:36:05 +0000 (UTC)

kenneth gonsalves <lawgon at ...> writes:


On Sat, 2011-12-31 at 10:59 +0530, kenneth gonsalves wrote:
a team of 3 people are playing. We need the sum of the best two
scores.

scores = [5,2,3]
scores.pop(scores.index(min(scores)))
2
sum(scores)
8

can this be done in one line? (first line which initialises the
variable
is not counted). 

solved:

scores = [5,2,3]
sum(sorted(scores)[1:3])
8

sum(sorted(scores)[-2:])

seems like a more general solution.

Regards,
Sameer





Other related posts: