[Tutor] (a, b) = (l[0:2], l[2:])

Lie Ryan lie.1296 at gmail.com
Wed May 13 12:34:28 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)
> 

that way is fine. Although usually it don't use parens and 0 is omitted...

a, b = l[:2], l[2:]

In python, direct index access is generally avoided whenever it is still 
possible to use for or other constructs (but practical beats purity, 
choose whatever method that produce a code that looks good and performs 
good enough)



More information about the Tutor mailing list