How to join two sets in one line without using “|”

前端 未结 8 1059
闹比i
闹比i 2020-12-23 00:21

Assume that S and T are assigned sets. Without using the join operator |, how can I find the union of the two sets? This, for example,

8条回答
  •  抹茶落季
    2020-12-23 00:41

    You could use or_ alias:

    >>> from operator import or_
    >>> from functools import reduce # python3 required
    >>> reduce(or_, [{1, 2, 3, 4}, {3, 4, 5, 6}])
    set([1, 2, 3, 4, 5, 6])
    

提交回复
热议问题