You can do the intersection using &
on set()
object:
>>> s1='da nesh gah'
>>> s2='dan esh gah'
>>> set(s1.split()) & set(s2.split())
set(['gah'])
Here, I am firstly converting the string to list of words using str.split()
. set()
will convert the list to set object, on which you can find intersection between two sets using &
.
If you prefer functional style, you can use set().intersection()
to get the same result:
>>> set(s1.split()).intersection(s2.split())
set(['gah'])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…