Python idiom should be : a, b = [], []

I remember having learn that in an presentation about idiomatic python, in
this presentation I think :
https://www.youtube.com/watch?v=OSGv2VnC0go&list=WL&index=14

:)

Richard

On Wed, Dec 9, 2015 at 3:25 PM, Ron McOuat <[email protected]> wrote:

> Are you sure you want to do that?
>
> a = b = []
>
> binds a and b to the same empty list object so whatever you do to a will
> also appear in b because they both reference the same list object.
> Assignment does not create a new object, it simply binds a variable name on
> the left to the object on the right.
>
> Try this:
>
> a = b = []
> a.insert(0,2)
> print a, b
>
> should print
> [2] [2]
>
> A great source of bugs if a and b are thought to be different objects.
>
> Ron
>
>
> On Tuesday, 8 December 2015 07:01:36 UTC-8, Mark Billion wrote:
>>
>> in python 2.6, I can run a = b = [] and get the expected result.  In W2P,
>> when I do it, it throws an exception as the list does not propagate to both
>> a & b.  It would make my code cleaner, but otherwise not a problem.  Just
>> wanted to give a shout in case anyone gave a ....
>>
>> Thanks again for all of your help!
>>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to