Skip to content

Commit 1bdeee8

Browse files
committed
wc function
1 parent 6828cfb commit 1bdeee8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

hw_2/olga_iter.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
def unique(l):
24
return list(set(l))
35

@@ -15,3 +17,18 @@ def divide(a, b):
1517
print(divide(4, False))
1618
print(divide(4, None))
1719
print(divide(4, 2))
20+
21+
22+
def wc(s):
23+
return {"symbols": len(re.findall(r'\w', s)),
24+
"words": len(re.findall(r'\w\w*', s)),
25+
"lines": s.count("\n") + 1}
26+
27+
s = """d ss
28+
ddd
29+
123_45f
30+
dd
31+
d"""
32+
33+
print(wc(s))
34+
print(re.findall(r'\w', s))

0 commit comments

Comments
 (0)