我不能確定什麼樣的用戶會進入,但我想打破他們的輸入句子分成單詞列表中的如何獲取用戶句子並從中創建單詞列表?
User_input = raw_input("Please enter a search criterion: ")
User_Input_list[""]
# input example: steve at the office
# compiling the regular expression:
keyword = re.compile(r"\b[aA-zZ]\b")
for word in User_input:
User_Input_list.append(word?)
# going by thin put example input I'd want
# User_Input_list["steve", "at" , "the" , "office"]
我不確定如何了拆分輸入單獨的詞?我會給餅乾幫忙!
這個工作是否會帶來整體感? – RY4N 2011-03-23 10:00:52
它可以處理任何類型的字符串並在空白字符上分割,就像字符串中的單詞一樣。 – poke 2011-03-23 10:07:07
@Ryan這將適用於任何字符串,以及來自@oleide和其他人的解決方案。 oleide的解決方案和我的解決方案之間的區別在於,我的解決方案分裂在任何空白區域,而他的解決方案只分裂在''(空間)角色上。這兩種方法都可以用於不同的情況。 – theheadofabroom 2011-03-23 10:51:50