Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4ce5f3f

Browse files
committed
improve idioms (closes #20642)
Patch by Claudiu Popa.
1 parent 98baa14 commit 4ce5f3f

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

Lib/copy.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,17 +221,15 @@ def _deepcopy_list(x, memo):
221221
d[list] = _deepcopy_list
222222

223223
def _deepcopy_tuple(x, memo):
224-
y = []
225-
for a in x:
226-
y.append(deepcopy(a, memo))
224+
y = [deepcopy(a, memo) for a in x]
227225
# We're not going to put the tuple in the memo, but it's still important we
228226
# check for it, in case the tuple contains recursive mutable structures.
229227
try:
230228
return memo[id(x)]
231229
except KeyError:
232230
pass
233-
for i in range(len(x)):
234-
if x[i] is not y[i]:
231+
for k, j in zip(x, y):
232+
if k is not j:
235233
y = tuple(y)
236234
break
237235
else:

0 commit comments

Comments
 (0)