Skip to content

Commit 466c007

Browse files
committed
wc: line and word count
1 parent 02de813 commit 466c007

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

  • implement-shell-tools/wc

implement-shell-tools/wc/wc.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,25 @@
88

99
args = parser.parse_args()
1010

11+
lines = 0
12+
words = 0
13+
bytes = 0
14+
1115
dict = {}
1216

1317
for file in args.path:
1418
f = open(file)
15-
text = []
16-
text.append(f.read())
17-
dict[file] = text
18-
19+
# text = []
20+
# text.append(f.read().split("\n"))
21+
# print(f.read().split("\n"))
22+
dict[file] = f.read().split("\n")
23+
# print(dict)
1924
for f in dict:
20-
print(dict[f])
25+
word_per_line = 0
26+
byte_per_line = 0
27+
for l in dict[f]:
28+
word_per_line += len(l.split())
29+
byte_per_line += len(l.encode("utf-8"))
30+
# print(byte_per_line)
31+
print(str(len(dict[f]) - 1) + " " + str(word_per_line) + " " + f)
2132

22-
# print(dict)

0 commit comments

Comments
 (0)