我想返回一个作为frozenset类型的列表,它的类型将通过返回函数来检查,如下所示
frozentSet = functionName(list1, list2)
if type(frozentSet) == frozenset:
print("Return value is a frozenset")
else:
print("Retrun value is not a frozenset")
每当我将任何列表作为“frozenset”返回时,它都会给出如下结果,而我想返回上面给出的 if 条件。
return frozenset(['a','b','c','d','e','f'])
Output:
['f']
['b']
['a']
['d']
['e']
Returned value is not a frozenset
谢谢你的及时回复。请看下面的完整代码。
def returnFrozenset(listA):
frsA = frozenset(listA)
return frsA
if __name__ == '__main__':
lst1_count = int(input().strip())
lst1 = []
for _ in range(lst1_count):
lst1_item = input()
lst1.append(lst1_item)
isFrozenSet = returnFrozenset(lst1)
print("Returned value is {1} frozenset".format(isFrozenSet, "a" if type(frset) == frozenset else "not a"))