[Tutor] Grouping based on attributes of elements in a List

Rafael Durán Castañeda rafadurancastaneda at gmail.com
Wed Mar 30 00:25:12 CEST 2011


>From python docs:

For non-negative indices, the length of a slice is the difference of the
indices, if both are within bounds. For example, the length of word[1:3] is
2.

Example:

>>> list_[1][1:3]
('LOOSEFREIGHT', 'MIXEDLCL')
>>>

As I said i think my approach is more pythonic, but I'm not absolutely sure.
With such approach I don't need importing, I use slicing and you are right,
your approach is more flexible and would work on more cases, but in this
particular case I still think unnecessary. Maybe someone else could tell us
which is the best option.

El 30 de marzo de 2011 00:14, Sander Sweers <sander.sweers at gmail.com>escribió:

> 2011/3/29 Rafael Durán Castañeda <rafadurancastaneda at gmail.com>:
> > And more pythonic, I think
>
> I don't agree :-). I think itemgetter from the operator module is more
> flexible, readable and elegant than using a lamda. How would you sort
> on the first and last item with lambda?
>
> Greets
> Sander
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110330/b17f47f0/attachment-0001.html>


More information about the Tutor mailing list