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

  • From: vkslist@xxxxxxxxx (Sameer)
  • Date: Sat, 31 Dec 2011 15:29:45 +0000 (UTC)

kenneth gonsalves <lawgon at ...> writes:

On Sat, 2011-12-31 at 10:36 +0000, Sameer wrote:
scores = [5,2,3]
sum(sorted(scores)[1:3])
8

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

seems like a more general solution. 

nice (but the same number of keystrokes )

:) I didn't even think about that. Actually, I was trying to figure out the
slice syntax (Python's has never been intuitive) and realised 1:3 is specific to
a 3-element list.





Other related posts: