小编Val*_*lav的帖子

删除自定义停用词形成python中的短语

我试图在进一步处理输入之前从用户输入中删除某些短语和单词,而在尝试这样做时,我遇到了“索引超出范围”错误的问题,并且完全卡住了。我该如何解决这个问题?我将输入短语作为字符串转换为列表以比较每个单词,并将停用词作为预定义列表。
示例输入:
["well","you","know","the","weather","is","awful"]
["you", "know", "what", "i", " mean", "so", "just", "turn", "the", "lights", "on"]

#Gets user input and removes the selected stop words from it and returns a filtered phrase back.    
def stop_word_remover(phrase_list):

    stop_words_lst = ["yo", "so", "well", "um", "a", "the","you know", "i mean"]

    #initalize clean phrase string
    clean_input_phrase= ""

    #copying phrase_list into a new variable for stopword removal.
    Copy_phrase_list = list(phrase_list)

    #Cleanup loop

    for i in range(1,len(phrase_list)):
        has_stop_words = False

        for x in range(len(stop_words_lst)):
            has_stop_words = False

            #if …
Run Code Online (Sandbox Code Playgroud)

python nlp stop-words python-2.7

1
推荐指数
1
解决办法
5812
查看次数

随机数发生器解释

from random import *
def main():
    t = 0
    for i in range(1000):  # thousand
        t += random()
    print(t/1000)
main()
Run Code Online (Sandbox Code Playgroud)

我正在查看我教授给我的示例程序的源代码,我遇到了这个RNG.谁能解释这个RNG的工作原理?

python random for-loop operators python-3.x

0
推荐指数
1
解决办法
334
查看次数

标签 统计

python ×2

for-loop ×1

nlp ×1

operators ×1

python-2.7 ×1

python-3.x ×1

random ×1

stop-words ×1