-
Notifications
You must be signed in to change notification settings - Fork 8
/
swearing.py
34 lines (29 loc) · 909 Bytes
/
swearing.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
import csv
# key value of censored words and their replacements
censored_words = {
'f******': 'ucking',
'f*****': 'ucks',
'f*****': 'ucked',
'f***': 'uck',
's***': 'hit',
's*******': 'hitting',
's***': 'hitty',
's****': 'hits',
'n*****': 'iggas',
'n****': 'igga',
'b****': 'itch',
}
def replace_censored_words():
with open('metadata.csv', 'r') as f:
reader = csv.reader(f)
metadata = list(reader)
for row in metadata:
for censored_word in censored_words:
# make a new variable that is censored_word without any *
first_letter = censored_word[0] + censored_words[censored_word]
row[0] = row[0].replace(censored_word, first_letter)
with open('metadata.csv', 'w') as f:
writer = csv.writer(f)
writer.writerows(metadata)
if __name__ == "__main__":
replace_censored_words()