We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 65425b4 commit f2ad18aCopy full SHA for f2ad18a
1 file changed
implement-shell-tools/wc/wc.py
@@ -2,12 +2,32 @@
2
3
args = sys.argv[1:]
4
5
-for path in args:
+option = "all"
6
+paths = []
7
+
8
+for arg in args:
9
+ if arg == "-l":
10
+ option = "l"
11
+ elif arg == "-w":
12
+ option = "w"
13
+ elif arg == "-c":
14
+ option = "c"
15
+ else:
16
+ paths.append(arg)
17
18
+for path in paths:
19
with open(path, "r") as file:
20
content = file.read()
21
- lines = content.split("\n")
- words = content.split(" ")
- chars = content
22
+ lines = len(content.split("\n"))
23
+ words = len(content.split(" "))
24
+ chars = len(content)
25
- print(len(lines), len(words), len(chars), path)
26
+ if option == "l":
27
+ print(lines, path)
28
+ elif option == "w":
29
+ print(words, path)
30
+ elif option == "c":
31
+ print(chars, path)
32
33
+ print(lines, words, chars, path)
0 commit comments