我正在使用frozenset,我想避免包含'frozenset'的输出。例如,我有
x = [frozenset([item]) for item in Set]
Output: frozenset(['yes']) => frozenset(['red', 'blue'])
有什么想法吗?
答案 0 :(得分:1)
您可以通过创建frozenset
的子类并覆盖其__repr__
方法来执行此操作:
class MyFrozenSet(frozenset):
def __repr__(self):
return '([{}])'.format(', '.join(map(repr, self)))
...
>>> lst = [['yes'], ['red', 'blue']]
>>> [MyFrozenSet(x) for x in lst]
[(['yes']), (['blue', 'red'])]