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.

7
  • 3
    but it's three statements rather than one expression
    – fortran
    Commented Oct 18, 2011 at 15:44
  • 17
    Yes! The mentioned one-expression-solutions are either slow or evil. Good code is readable and maintainable. So the problem is the question not the answer. We should ask for the best solution of a problem not for a one-line-solution.
    – phobie
    Commented Oct 28, 2011 at 3:36
  • 11
    Lose the z4 = {} and change the next line to z4 = x.copy() -- better than just good code doesn't do unnecessary things (which makes it even more readable and maintainable).
    – martineau
    Commented Mar 8, 2013 at 15:10
  • 3
    Your suggestion would change this to Matthews answer. While his answer is fine, I think mine is more readable and better maintainable. The extra line would only be bad if it would cost execution time.
    – phobie
    Commented May 6, 2013 at 11:50
  • I suggest you put this into a function
    – Corman
    Commented Jun 14, 2020 at 23:16