Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python中两个Unicode数组的交集_Python_Arrays_Unicode_Intersection_Hindi - Fatal编程技术网

Python中两个Unicode数组的交集

Python中两个Unicode数组的交集,python,arrays,unicode,intersection,hindi,Python,Arrays,Unicode,Intersection,Hindi,我的计划的运作: 1从文件test.txt中搜索包含单词的行साधु . 2在搜索该行之后,我提取其左右两侧相邻的单词。 3在将这些单词添加到数组后,我尝试在这两个数组中查找相交的单词。您可以使用以下代码将字符串解码为unicode mylist = map(lambda word: word.decode('utf-8'), mylist) 尽管出于交叉的目的,您不需要对其进行解码。你可以这么做 #considering you have two lists 'list1' and 'lis

我的计划的运作: 1从文件test.txt中搜索包含单词的行साधु . 2在搜索该行之后,我提取其左右两侧相邻的单词。
3在将这些单词添加到数组后,我尝试在这两个数组中查找相交的单词。

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

mylist = map(lambda word: word.decode('utf-8'), mylist)
尽管出于交叉的目的,您不需要对其进行解码。你可以这么做

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

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

这就是你想要的吗{“”、'\xa4'、'\xa5'、'\xe0'}交叉点是setarray1&setarray2,即使使用印地语单词数组,除非我遗漏了一些东西….?对不起,这对我不起作用。你能告诉我如何找到这两个数组之间的交集吗列表1=[1,2,3,4,'साधु ', ' बालक '] 列表2=[1,3,5,6,'साधु ', ' बालक ']例如,在您提到的示例中,它是有效的,只有您可能将结果作为字节字符串而不是unicode获取object@vashi结果=设置列表1。intersectionsetlist2@hspandher,如何在实际字符串unicode对象中获得结果?@Dmitry.Samborskyi,交集工作,它以字节字符串形式给出结果。如何获得实际字符串?