[Tutor] Calculate hours

Peter Otten __peter__ at web.de
Fri Jan 25 22:42:15 CET 2013


शंतनू wrote:

> s = [sum(x) for x in matrix]
> for q in sorted([(x,y) for x,y in enumerate(s)],
> key=operator.itemgetter(1)):
>     print("Employee %d has worked %d hours" % (q[0], q[1]))
 
A minor simplification:

s = (sum(x) for x in matrix)
for q in sorted(enumerate(s), key=operator.itemgetter(1)):
    print("Employee %d has worked %d hours" % q)



More information about the Tutor mailing list