无法在Python中分解“string.replace”

时间:2013-11-26 22:57:42

标签: python

我已经为计算机科学设定了一个实验室问题,我真的很难掌握它。为了学习的目的,我们不允许使用“内置”功能,即“ string.replace()“在这个例子中..

我已经定义了一个函数来从输入字符串中删除“stop-words”并且无法使其正常工作,任何人都可以看到下面发生的任何问题吗?

干杯,

import string
text = raw_input ( " Please Enter Here: ")

def removePunctuation(text_input):
    line = []
    i = 0
    total_text = ""
    new_char_string = ""
    for char in text_input:
        if char in string.punctuation:
            char = ""

        new_char_string = new_char_string + char

    line = line + [new_char_string.lower()]
    total_text = (total_text + new_char_string).lower()
    return line

print removePunctuation(text)< --- Fix for Friday ...

def removeStopWords(text_input):
    line_stop_words = []
    stop_words = "a","It","i","it","am","at","on","in","of","to","is","so","too","my","The","the","and","but","are","very","here","even","from","them","then","than","this","that","though"
word = ""
for word in text_input:
    word_list = string.split(text_input)
    new_string = ""
    for word in word_list:
        if word in stop_words:
            new_string = new_string + word + " "
    new_string = string.split(new_string)
    line_stop_words = line_stop_words + [new_string]
return(line_stop_words)

print removeStopWords(text)

0 个答案:

没有答案