[Tutor] Multiple lists from single list with nested lists

Kent Johnson kent37 at tds.net
Wed Oct 22 04:01:29 CEST 2008

On Tue, Oct 21, 2008 at 5:09 PM, Sander Sweers <sander.sweers at gmail.com> wrote:

> This did not work but the below did ;-)
> templist = [ somelist[:1] + [x] + somelist[3:] for x in somelist[2] ]

somelist[:1] doesn't include somelist[1] so I think you are missing
one element of your original list.

List slices like [0:2] or [:1] are up-to-but-not-including the second index.


More information about the Tutor mailing list