[Python-ideas] Why operators are useful

Steven D'Aprano steve at pearwood.info
Sat Mar 16 07:00:59 EDT 2019


On Sat, Mar 16, 2019 at 06:43:52AM +0400, Abdur-Rahmaan Janhangeer wrote:
> Despite my poor python skills, i don't think i'd ever use this one.
> 
>         blocks = blocks + [block]              # Not good for you.

Neither would I. But I would use:


    result = process(blocks + [block])


in preference to:

    temp = blocks[:]
    temp.append(block)
    result = process(temp)
    del temp  # don't pollute the global namespace


Can I make it clear that the dict addition PEP does not propose 
deprecating or removing the update method? If you need to update a dict 
in place, the update method remains the preferred One Obvious Way to do 
so, just as list.append remains the One Obvious Way to append to a 
list.


-- 
Steven


More information about the Python-ideas mailing list