Python 输入字符串列表

Python 输入字符串列表,python,string,similarity,Python,String,Similarity,我修改了一个Python代码来创建一个简单的字符串相似性 但是,我尝试做的是一个用户输入,我希望第二个用户输入(单词)包含一个单词列表,以便我可以比较单词之间的差异 ''' Input the English words in w1, and the translated Malay words in the list ''' w1 = raw_input("Enter the English word: ") words = raw_input("Enter all the Malay

我修改了一个Python代码来创建一个简单的字符串相似性

但是,我尝试做的是一个用户输入,我希望第二个用户输入(单词)包含一个单词列表,以便我可以比较单词之间的差异

    '''
Input the English words in w1, and
the translated Malay words in the list
'''
w1 = raw_input("Enter the English word: ")
words = raw_input("Enter all the Malay words: ")
## The bits im not sure what to code
wordslist = list(words)

for w2 in wordslist:
    print(w1 + ' --- ' + w2)
    print(string_similarity(w1, w2))
    print
当我输入时,它似乎使整个“w1”输入与字符串相似,所有单个字符都在“Word”输入中。我想要的只是一个例子

w1=联合王国 单词=联合王国,联合王国,美国,Kingdmo

然后它在哪里进行测量

United Kingdom --- United Kingdom
United Kingdom --- United Kingdoms
United Kingdom --- United Sates
United Kingdom --- Kingdmo
等等


谢谢你的帮助

您可以使用
str.split
获取单词列表:

>>> strs = "United Kingdom, United Kingdoms, United States, Kingdmo"
>>> strs.split(",")
['United Kingdom', ' United Kingdoms', ' United States', ' Kingdmo']
帮助关于
str.split

>>> str.split?
Namespace:  Python builtin
Docstring:
S.split([sep [,maxsplit]]) -> list of strings

Return a list of the words in the string S, using sep as the
delimiter string.  If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are removed
from the result.

您可以使用
str.split
获取单词列表:

>>> strs = "United Kingdom, United Kingdoms, United States, Kingdmo"
>>> strs.split(",")
['United Kingdom', ' United Kingdoms', ' United States', ' Kingdmo']
帮助关于
str.split

>>> str.split?
Namespace:  Python builtin
Docstring:
S.split([sep [,maxsplit]]) -> list of strings

Return a list of the words in the string S, using sep as the
delimiter string.  If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are removed
from the result.

很抱歉问了一个愚蠢的问题,但是我如何通过用户输入来实现这一点呢?我尝试在用户输入下使用str.split(“,”),它仍然单独处理字符串(每个字符)。谢谢@user1433571用户输入的单词必须用逗号分隔(类似于您发布的问题)。然后使用
words=words.split(“,”)
。很抱歉问了一个愚蠢的问题,但我如何从用户输入中实现这一点?我尝试在用户输入下使用str.split(“,”),它仍然单独处理字符串(每个字符)。谢谢@user1433571用户输入的单词必须用逗号分隔(类似于您发布的问题)。然后使用
words=words.split(“,”)