From 151e8b8c630a89d2267e05ac17ef7461ec229cd9 Mon Sep 17 00:00:00 2001 From: Mahmoud Hashemi Date: Wed, 20 Mar 2013 04:41:09 -0700 Subject: [PATCH] add some notes on IndexedSet --- boltons/setutils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/boltons/setutils.py b/boltons/setutils.py index 795acfd..6221ddd 100644 --- a/boltons/setutils.py +++ b/boltons/setutils.py @@ -38,6 +38,18 @@ class IndexedSet(MutableSet): >>> fcr = IndexedSet('freecreditreport.com') >>> ''.join(fcr[:fcr.index('.')]) 'frecditpo' + + For the curious, the reason why IndexedSet does not support + __setitem__() (i.e, setting items based on index), and is not a + UniqueList, consider the following: + + my_indexed_set = [A, B, C, D] + my_indexed_set[2] = A + + At this point, a set requires only one A, but a list would + overwrite C. Overwriting C would change the length of the list, + meaning that my_indexed_set[2] would not be A, as expected with a + list, but rather D. So, no __setitem__(). """ def __init__(self, other=None): self.item_index_map = dict()