[Python-ideas] [Python-Dev] One obvious way to do interning [Was: Retrieve an arbitrary element from a set without removing it]
Nick Coghlan
ncoghlan at gmail.com
Mon Oct 26 22:50:56 CET 2009
Terry Reedy wrote:
> Alexander Belopolsky wrote:
>> Terry Reedy wrote:
>>> I had exactly the same idea, but did not post because it violates the
>>> general rule that mutators return None.
>>
>> Is there such a rule? What about set/dict pop?
>
> The rule perhaps should be restated as 'Collection mutators return None
> or possible an item but not the collection.'
And to clarify the rationale for that guideline: it is to make it clear
that the mutator is changing the container in place and *not* creating a
new container object.
myset.pop() # No new container, returns popped object
mylist.sort() # No new container, returns None
sorted(mylist) # New container, so return it
mystr.lower() # Creates new string, so return it
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-ideas
mailing list