Skip to content

Commit 58bf5c9

Browse files
added comments
1 parent d8f62e6 commit 58bf5c9

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

CountMillionCharacter.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"""
99
import re
1010

11-
pattern = re.compile("\W")
11+
pattern = re.compile("\W") #re is used to compile the expression more than once
12+
#wordstring consisting of a million characters
1213
wordstring = '''SCENE I. Yorkshire. Gaultree Forest.
1314
Enter the ARCHBISHOP OF YORK, MOWBRAY, LORD HASTINGS, and others
1415
ARCHBISHOP OF YORK
@@ -293,17 +294,17 @@
293294
Before, and greet his grace: my lord, we come.
294295
Exeunt'''
295296

296-
wordlist = wordstring.split()
297+
wordlist = wordstring.split() #splits each word with a space
297298

298299
for x, y in enumerate(wordlist):
299-
special_character = pattern.search(y[-1:])
300+
special_character = pattern.search(y[-1:]) #searches for a pattern in the string
300301
try:
301-
if special_character.group():
302+
if special_character.group(): #returns all matching groups
302303
wordlist[x] = y[:-1]
303304
except:
304305
continue
305306

306-
wordfreq = [wordlist.count(w) for w in wordlist]
307+
wordfreq = [wordlist.count(w) for w in wordlist] #counts frequency of a letter in the list
307308

308309
print("String\n {} \n".format(wordstring))
309310
print("List\n {} \n".format(str(wordlist)))

0 commit comments

Comments
 (0)