How to access the low digits of a list

Ian Kelly ian.g.kelly at gmail.com
Tue Jun 2 10:19:39 EDT 2015


On Tue, Jun 2, 2015 at 6:35 AM, Rustom Mody <rustompmody at gmail.com> wrote:
> For that matter even this works
> But I am not sure whats happening or that I like it
>
>>>> [x[-2:]  for x in lines]
> ['12', '42', '49', '56', '25', '36', '49', '64', '81', '00']

x[-2:] selects all items in the sequence with index i such that len(x)
- 2 <= i < len(x). For a sequence of length 2 or less, that's the
entire sequence.



More information about the Python-list mailing list