How to get an arbitrary element from a frozenset?
问题 I would like to get an element from a frozenset (without modifying it, of course, as frozenset s are immutable). The best solution I have found so far is: s = frozenset(['a']) iter(s).next() which returns, as expected: 'a' In other words, is there any way of 'popping' an element from a frozenset without actually popping it? 回答1: (Summarizing the answers given in the comments) Your method is as good as any, with the caveat that, from Python 2.6, you should be using next(iter(s)) rather than