Can a List Comprehension do ____ ?
Steven Bethard
steven.bethard at gmail.com
Wed Jul 14 19:01:42 EDT 2004
Steve <lonetwin at gmail.com> wrote in message news:<mailman.360.1089792115.5135.python-list at python.org>...
> so the LC is:
> a) return a list :
> []
> b) iterating over every element in 'breaks', using it's index:
> [ for i in range(len(breaks)) ]
> c) and return the max() of the i'th element and the min() of it's
> successive element:
> [ (max(b[i]), min(b[i+1])) for i in range(len(breaks)) ]
> d) remembering that there would be no successive element for the last
> element in the list:
> [ (max(b[i]), min(b[i+1])) for i in range(len(breaks)) if i+1
> < len(breaks) ]
>
> HTH
> Steve
Or, slightly more concicely, though perhaps less readably:
[(breaks[i][1], breaks[i+1][0]) for i in range(len(breaks) - 1)]
Steve
More information about the Python-list
mailing list