Case-insensitive comparison of sets in Python

后端 未结 4 1034

I have two sets (although I can do lists, or whatever):

a = frozenset((\'Today\',\'I\',\'am\',\'fine\'))
b = frozenset((\'hello\',\'how\',\'are\',\'you\',\'t         


        
4条回答
  •  别那么骄傲
    2021-01-19 15:44

    >>> a_, b_ = map(set, [map(str.lower, a), map(str.lower, b)])
    >>> a_ & b_
    set(['today'])
    

    Or... with less maps,

    >>> a_ = set(map(str.lower, a))
    >>> b_ = set(map(str.lower, b))
    >>> a_ & b_
    set(['today'])
    

提交回复
热议问题