是否有一个`stdlib`或`pandas`等同于以下简单的`is_in`函数?

时间:2015-10-21 16:43:57

标签: python list

是否有Exception in thread "main" java.io.FileNotFoundException: file:\C:\Users\DeLL\Desktop\BoxcraftClient\ClientInstaller.jar!\client.bxc (The filename, directory name, or volume label syntax is incorrect) at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.<init>(ZipFile.java:220) at java.util.zip.ZipFile.<init>(ZipFile.java:150) at java.util.zip.ZipFile.<init>(ZipFile.java:164) at Launcher.install(Launcher.java:43) at Launcher.main(Launcher.java:33) stdlib等效于以下简单pandas功能? (看起来很简单,但我还没有找到它)

is_in

同样的事情:

def is_in(x, y):
'''
:param x: a list of values of length n
:param y: a list of values of any length
:return: a list of Boolean values, corresponding to if
 each value in x is in y.

Example:
x = [1,15,[1,2,3],'a', 'Sandy', {'a':[4]}]
y = [[1,2,3], 15, 'Sand', {'a':[4]}]
is_in(x,y)
# returns:
# [False, True, True, False, False, True]
'''
idx = [xx in y for xx in x]
return idx

1 个答案:

答案 0 :(得分:2)

可能最快:

map(y.__contains__, x)

对于问题的第二部分,有itertools.compress