]> granicus.if.org Git - python/commitdiff
Use generator instead of list in code examples (GH-11203)
authorRecursing <buonanno.lorenzo@gmail.com>
Sun, 23 Dec 2018 03:48:14 +0000 (04:48 +0100)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>
Sun, 23 Dec 2018 03:48:14 +0000 (19:48 -0800)
There is no need to create a list for `sum`
Also, becomes consistent with the first example in Doc/library/os.rst

Lib/os.py

index 4b31e4dcc8add6dee4f3507aed9fa48f54dface7..7741c7580d0e3bc0b412859817593f157706e5f9 100644 (file)
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -327,7 +327,7 @@ def walk(top, topdown=True, onerror=None, followlinks=False):
     from os.path import join, getsize
     for root, dirs, files in os.walk('python/Lib/email'):
         print(root, "consumes", end="")
-        print(sum([getsize(join(root, name)) for name in files]), end="")
+        print(sum(getsize(join(root, name)) for name in files), end="")
         print("bytes in", len(files), "non-directory files")
         if 'CVS' in dirs:
             dirs.remove('CVS')  # don't visit CVS directories
@@ -446,7 +446,7 @@ if {open, stat} <= supports_dir_fd and {scandir, stat} <= supports_fd:
         import os
         for root, dirs, files, rootfd in os.fwalk('python/Lib/email'):
             print(root, "consumes", end="")
-            print(sum([os.stat(name, dir_fd=rootfd).st_size for name in files]),
+            print(sum(os.stat(name, dir_fd=rootfd).st_size for name in files),
                   end="")
             print("bytes in", len(files), "non-directory files")
             if 'CVS' in dirs: