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

Skip to content

Commit 3ce3dea

Browse files
Recursingrhettinger
authored andcommitted
Use generator instead of list in code examples (GH-11203)
There is no need to create a list for `sum` Also, becomes consistent with the first example in Doc/library/os.rst
1 parent fc8284e commit 3ce3dea

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

Lib/os.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
327327
from os.path import join, getsize
328328
for root, dirs, files in os.walk('python/Lib/email'):
329329
print(root, "consumes", end="")
330-
print(sum([getsize(join(root, name)) for name in files]), end="")
330+
print(sum(getsize(join(root, name)) for name in files), end="")
331331
print("bytes in", len(files), "non-directory files")
332332
if 'CVS' in dirs:
333333
dirs.remove('CVS') # don't visit CVS directories
@@ -446,7 +446,7 @@ def fwalk(top=".", topdown=True, onerror=None, *, follow_symlinks=False, dir_fd=
446446
import os
447447
for root, dirs, files, rootfd in os.fwalk('python/Lib/email'):
448448
print(root, "consumes", end="")
449-
print(sum([os.stat(name, dir_fd=rootfd).st_size for name in files]),
449+
print(sum(os.stat(name, dir_fd=rootfd).st_size for name in files),
450450
end="")
451451
print("bytes in", len(files), "non-directory files")
452452
if 'CVS' in dirs:

0 commit comments

Comments
 (0)