How to extract the member from single-member set in python?

前端 未结 6 1304
感动是毒
感动是毒 2020-12-23 18:46

I recently encountered a scenario in which if a set only contained a single element, I wanted to do something with that element. To get the element, I settled on this appro

6条回答
  •  滥情空心
    2020-12-23 19:19

    There is also Extended Iterable Unpacking which will work on a singleton set or a mulit-element set

    element, *_ = myset

    Though some bristle at the use of a throwaway variable.

提交回复
热议问题