# Multiple equates

Diez B. Roggisch deets at nospam.web.de
Mon Nov 17 20:25:38 CET 2008

```Arnaud Delobelle wrote:

> jzakiya <jzakiya at mail.com> writes:
>
>> I looked online and in books, but couldn't find a definitive answer to
>> this.
>>
>> I have an array and set multiple elements to either True or False at
>> one time.
>>
>> Question: Which way is faster (or does it matter)?
>>
>> 1)
>>
>> array[x1]=array[x2]=........= array[x10] = \
>> array[x11]=array[x12]=... = array[x20] = \
>> ......
>> ......
>> array[x40]=array[x41]=....= array[x50] = False (or True)
>>
>>
>> 2)
>>
>> array[x1]=array[x2]=........= array[x10] = False
>> array[x11]=array[x12]=... = array[x20] = False
>> ......
>> ......
>> array[x40]=array[x41]=....= array[x50] = False
>
> It doesn't matter as none of this is valid Python. In Python you have to
> write
>
> array[x1] = False
> array[x2] = False
>
> Etc...
>

No.

l = range(10)
l[0] = l[1] = 100

And there seems to be a small difference between both versions,
but I can't judge for sure if that favors one of them - yet I tend to think
it's not worth the effort...

import dis

def a():
l = range(10)
l[0] = l[1] = 100

def b():
l = range(10)
l[0] = 100
l[1] = 100

print "------------ a ---------------"
dis.dis(a)
print "------------ b ---------------"
dis.dis(b)

------------ a ---------------
6 CALL_FUNCTION            1
9 STORE_FAST               0 (l)

*            15 DUP_TOP
22 STORE_SUBSCR
29 STORE_SUBSCR
33 RETURN_VALUE
------------ b ---------------
6 CALL_FUNCTION            1
9 STORE_FAST               0 (l)

21 STORE_SUBSCR

31 STORE_SUBSCR