im writing a spellchecking program, how do i replace ch in a string..eg..

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:10 UTC
Read the original article Hit count: 238

Filed under:
|

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)

p.s, this is in Python 3.1.2

© Stack Overflow or respective owner

Related posts about string

Related posts about Operations