Skip to content

Commit cff53ea

Browse files
committed
solved problem 22 and partialy problem 23
1 parent c9e6524 commit cff53ea

File tree

3 files changed

+7655
-0
lines changed

3 files changed

+7655
-0
lines changed

Chapter 6/problems/Problem6_22.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
def mirror(string):
2+
newstring = ''
3+
dictionary = {'d':'b', 'b':'d','p':'q', 'q':'p'}
4+
for i in range(-1, -len(string)-1, -1):
5+
if string[i] in 'aeiu':
6+
return 'INVALID'
7+
elif string[i] in dictionary.keys():
8+
newstring += dictionary[string[i]]
9+
else:
10+
newstring += string[i]
11+
return newstring
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def scaryDict(filename):
2+
file = open(filename)
3+
content = file.read()
4+
file.close()
5+
for symbol in '!?,;.-"()[]1234567890':
6+
content = content.replace(symbol, '')
7+
content = content.split()
8+
for word in content:
9+
if len(word) < 3:
10+
content.remove(word)
11+
content = list(set(content))
12+
content.sort()
13+
newfile = ''
14+
for word in content:
15+
newfile += word + '\n'
16+
file = open('dictionary.txt', 'w')
17+
file.write(newfile)
18+
file.close()
19+
print(newfile)

0 commit comments

Comments
 (0)