# 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
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}