Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 110
    To clarify why this doesn't meet the critera provided by the question: it's not a single expression and it doesn't return z. Commented Mar 21, 2013 at 13:15
  • 24
    Put it this way: if you need to put two lines of comments explaining your one line of code to the people you hand your code off to...have you really done it in one line? :) I fully agree Python is not good for this: there should be a much easier way. While this answer is more pythonic, is it really all that explicit or clear? Update is not one of the "core" functions that people tend to use a lot.
    – eric
    Commented Oct 19, 2017 at 13:07
  • 17
    Well, if people insist on making it a oneliner, you can always do (lambda z: z.update(y) or z)(x.copy()) :P
    – towr
    Commented Feb 24, 2020 at 12:43
  • 2
    @AlexanderOh I am not sure whenever this is a joke or not; I see this as a perfectly (valid) answ! (at least in terms of it works) but Of course; yeah; the second comment sets a precedent! either way; it is Indeed pythonic! Commented Jul 15, 2022 at 4:08
  • 9
    @WilliamMartens it wasn't a joke. But let's face it, if you optimize for single line expressions,you are optimizing for the wrong thing. Commented Jul 15, 2022 at 9:15