gpt4 book ai didi

Python:frozensets 比较

转载 作者:行者123 更新时间:2023-11-30 22:44:37 24 4
gpt4 key购买 nike

考虑以下脚本:

# multipleSmallFrozensets is a list of 7 frozensets of differenet number of string objects
multipleSmallFrozensets = [
frozenset({'YHR007C', 'YHR042W'}),
frozenset({'YPL274W'}),
frozenset({'YCL064C'}),
frozenset({'YBR166C'}),
frozenset({'YEL041W', 'YJR049C'}),
frozenset({'YGL142C'}),
frozenset({'YJL134W', 'YKR053C'})]

# singleFrozenset is a frozenset of 3410 string objects
singleFrozenset = frozenset({'YIL140W','YLR268W','YLR357W','YJL155C','YHR067W',
'YAL008W','YBR255W','YFR027W','YGR148C','YJR122W','YJL204C','YJL093C','YLR244C',
'YNL003C','YBR111W-A', ...})

# don't forget that i is of type frozenset [just saying!]
for i in multipleSmallFrozensets:
if i <= singleFrozenset: print "First option entered"
elif len(i) == 1: print "Second option entered"
else: print "Third option entered"

神秘的输出是

First option entered
Second option entered
Second option entered
First option entered
Third option entered
First option entered
First option entered

这些 if-else 条件检查两种情况 a) i <= singleFrozenset 和 b) len(i) == 1。第二个条件很简单;但是,我无法弄清楚第一个条件,其中匹配的案例是 1、4、6 和 7。在这些案例中,我找不到这些卡住集之间的链接!知道为什么吗?

最佳答案

集合运算符<=相当于 .issubset()方法。 A <= B当且仅当 A 的每个元素也属于 B 时才成立。

关于Python:frozensets 比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41476711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com