Skip to main content
9 events
when toggle format what by license comment
Sep 6 at 0:53 comment added wjandrea Oh, even better is to avoid creating a new list unnecessarily: sum(len(d)+len(f) ...
S Sep 3 at 15:45 history suggested wjandrea CC BY-SA 4.0
Add a header for each solution. Clarify: `-b` won't "have" non-printable characters raw, but escape them. Use Python 3 print syntax, which is also valid in Python 2.
Sep 3 at 13:28 comment added wjandrea I submitted a suggestion to have os.walk() default to the current dir :)
Sep 3 at 13:04 comment added wjandrea oops, os.walk() requires an argument. Still, os.listdir() doesn't.
Sep 3 at 13:02 comment added wjandrea Don't build a list just to get its len; use sum instead. Also, you can use unpacking instead of indexing into i. So: python -c 'import os; print(sum(len(d+f) for (_p, d, f) in os.walk(".")))'
Sep 3 at 12:58 review Suggested edits
S Sep 3 at 15:45
Sep 3 at 12:56 comment added wjandrea os.sep??? That's /, i.e. the root dir. Did you mean ".", for the current directory? You can actually remove the argument entirely (os.listdir()) and it'll automatically use the current dir.
Dec 23, 2011 at 16:45 history edited Arcege CC BY-SA 3.0
Add solution in Python
Dec 23, 2011 at 15:33 history answered Arcege CC BY-SA 3.0