Difference between tuples and frozensets in Python

后端 未结 4 1643
面向向阳花
面向向阳花 2020-12-29 00:49

I\'m learning Python 3 using The Quick Python Book, where the author talks about frozensets, stating that since sets are mutable and hence unhashable, thereby becoming unfit

4条回答
  •  醉梦人生
    2020-12-29 01:26

    One difference that comes to mind is the issue of duplicates. A tuple of (1, 1, 1, 1, 2, 2, 2) would be exactly what you expect, but a frozenset would remove all of those duplicates, leaving you with frozenset([1, 2]).

提交回复
热议问题