Python中两个Unicode数组的交集

时间:2015-08-27 12:38:18

标签: python arrays unicode intersection hindi

我的计划的工作: 1)从文件test.txt中搜索包含单词“साधु”的行。 2)在搜索线之后,我提取与其右边和左边相邻的单词。 3)在将这些单词附加到数组后,我尝试在这两个数组中找到相交的单词。

1 个答案:

答案 0 :(得分:2)

您可以使用以下代码将字符串解码为unicode

mylist = map(lambda word: word.decode('utf-8'), mylist)

虽然出于交叉目的,您无需对其进行解码。你可以做到

#considering you have two lists 'list1' and 'list2'

intersection = set(list1).intersection(set(list2))