-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmirror_characters.py
35 lines (31 loc) · 1.04 KB
/
mirror_characters.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import string
# import one library common string operations
# function that finds and returns the mirror string based on the sum of 128
def mirror_strings(x):
if(x!=' ' and x!='\n'):
point=128-ord(x)
end_point=chr(point)
elif (x==' '):
end_point=' '
elif (x=='\n'):
end_point='\n'
return end_point
str_nothing=""
general=[] # list that stores the content of the file by character
words_list=[] # list that stores the mirror strings of the file reversed
file=open("filename128.txt","r+")
data=file.read()
# the whitespace is being replaced by the whitespace and * and then when this special character
# is found the text is being splitted in a list
words=(data.replace(' '," *")).split("*")
for i in words:
for k in i:
general.append(k)
for j in general:
check=mirror_strings(j)
words_list.append(check)
words_list.reverse() # method that reverses the content of the file in place
for l in words_list:
str_nothing+=l
print(str_nothing)
file.close()