[Tutor] Calculate hours
Dave Angel
d at davea.name
Thu Jan 24 00:19:13 CET 2013
On 01/23/2013 06:13 PM, Alan Gauld wrote:
> On 23/01/13 03:08, Mitya Sirenef wrote:
>
>> To make the change you need, use list comprehension to make sums of all
>> rows, sort it (using list sort method); iterate over it using
>> enumerate() and print out "employee N, sum of hours:"
>
> One problem with that approach is that the employees are identified by
> their index in the original row so you probably need to maintain a note
> of that index. So before sorting you might want to create a tuple
> with the id and the values then sort on the second element. Only
> slightly more complex...
>
Complex or not, the first question is whether the OP's class has covered
sorting yet. And especially supplying key functions. I suspect not.
BTW, if I were building the tuples, I'd just let the key value be first,
and the index be second. That way the default key function works great.
--
DaveA
More information about the Tutor
mailing list