How to create the union of many sets using a generator expression?

后端 未结 3 1317
天命终不由人
天命终不由人 2020-12-01 07:44

Suppose I have a list of sets and I want to get the union over all sets in that list. Is there any way to do this using a generator expression? In other words, how can I cre

3条回答
  •  [愿得一人]
    2020-12-01 08:13

    Nested generator expression. But I think they are a bit cryptic, so the way KennyTM suggested may be clearer.

    frozenset(some_item for some_set in some_sets for some_item in some_set)
    

提交回复
热议问题