1

How is the code below possible?

>>> frozenset(('a_')) == frozenset(['a_'])
False
>>> frozenset(('a')) == frozenset(['a'])
True

My understanding is that so long as each each element of the iterable is hashable, a frozen set will be instantiated with each element being an element of the given iterable. I expect that both expressions above should return True.

Dipen Gajjar
  • 1,338
  • 14
  • 23
Greg
  • 193
  • 1
  • 1
  • 11
  • 2
    `('a_')` isn't a tuple. `('a_')` is just `'a_'`. – user2357112 Jun 05 '19 at 03:04
  • I see, so since a string is an iterable, `frozenset` will construct a set from each character of `a_`, which means `frozenset(['a', '_']) == frozenset(('a_'))` evaluates to `True`. – Greg Jun 05 '19 at 05:19

0 Answers0