]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
improve idioms (closes #20642)
authorBenjamin Peterson <benjamin@python.org>
Sun, 4 May 2014 00:22:00 +0000 (20:22 -0400)
committerBenjamin Peterson <benjamin@python.org>
Sun, 4 May 2014 00:22:00 +0000 (20:22 -0400)
Patch by Claudiu Popa.

Lib/copy.py

index bb8840ed549a5975a2e03b57b9f652e0608beb66..383609bc648f832e1cda3c5ad01a3b4b08636462 100644 (file)
@@ -221,17 +221,15 @@ def _deepcopy_list(x, memo):
 d[list] = _deepcopy_list
 
 def _deepcopy_tuple(x, memo):
-    y = []
-    for a in x:
-        y.append(deepcopy(a, memo))
+    y = [deepcopy(a, memo) for a in x]
     # We're not going to put the tuple in the memo, but it's still important we
     # check for it, in case the tuple contains recursive mutable structures.
     try:
         return memo[id(x)]
     except KeyError:
         pass
-    for i in range(len(x)):
-        if x[i] is not y[i]:
+    for k, j in zip(x, y):
+        if k is not j:
             y = tuple(y)
             break
     else: