I'm writing a spellchecking program, how do I replace ch in a string?
Posted
by Ajay Hopkins
on Stack Overflow
See other posts from Stack Overflow
or by Ajay Hopkins
Published on 2010-05-23T23:08:50Z
Indexed on
2010/05/23
23:20 UTC
Read the original article
Hit count: 278
What am I doing wrong/what can I do?
import sys
import string
def remove(file):
punctuation = string.punctuation
for ch in file:
if len(ch) > 1:
print('error - ch is larger than 1 --| {0} |--'.format(ch))
if ch in punctuation:
ch = ' '
return ch
else:
return ch
ref = (open("ref.txt","r"))
test_file = (open("test.txt", "r"))
dictionary = ref.read().split()
file = test_file.read().lower()
file = remove(file)
print(file)
This is in Python 3.1.2
© Stack Overflow or respective owner