# [Tutor] Calculate hours

शंतनू shantanoo at gmail.com
Fri Jan 25 22:08:05 CET 2013

```Reply inline.

On 23/01/13 8:22 AM, anthonym wrote:
> Hello All,
>
> I originally wrote this program to calculate and print the employee
> with the most hours worked in a week.  I would now like to change this
> to calculate and print the hours for all 8 employees in ascending order.
>
> The employees are named employee 0 - 8
>
> Any ideas?
>
> Thanks,
> Tony
>
> Code below:
>
>
>
> # Create table of hours worked
>
> matrix = [
>     [2, 4, 3, 4, 5, 8, 8],
>     [7, 3, 4, 3, 3, 4, 4],
>     [3, 3, 4, 3, 3, 2, 2],
>     [9, 3, 4, 7, 3, 4, 1],
>     [3, 5, 4, 3, 6, 3, 8],
>     [3, 4, 4, 6, 3, 4, 4],
>     [3, 7, 4, 8, 3, 8, 4],
>     [6, 3, 5, 9, 2, 7, 9]]
>

===
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]))
===

Output:

Employee 2 has worked 20 hours
Employee 1 has worked 28 hours
Employee 5 has worked 28 hours
Employee 3 has worked 31 hours
Employee 4 has worked 32 hours
Employee 0 has worked 34 hours
Employee 6 has worked 37 hours
Employee 7 has worked 41 hours

```