[Tutor] (a, b) = (l[0:2], l[2:])
Christian Witts
cwitts at compuscan.co.za
Wed May 13 12:36:26 CEST 2009
Jabin Jezreel wrote:
> What is the idiomatic way to write the right side of
> (a, b) = (l[0:2], l[2:])
> ?
> (not worried about the parens, just the splitting of the sequence)
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
What you are doing is already fine although you can drop the starting
index for the first slice
>>> l=[1,2,3,4,5,6,7,8,9,10]
>>> l[:2], l[2:]
([1, 2], [3, 4, 5, 6, 7, 8, 9, 10])
--
Kind Regards,
Christian Witts
More information about the Tutor
mailing list