Movatterモバイル変換


[0]ホーム

URL:


[Python-ideas] unify usage of mutable and immutable objects

David Mertzmertz at gnosis.cx
Tue Feb 28 18:14:33 EST 2017


On Tue, Feb 28, 2017 at 2:57 PM, 语言破碎处 <mlet_it_bew at 126.com> wrote:> 1) coverting to set or list is O(n) in time>A hypothetical frozenset.pop() is also necessarily O(N).  It needs to copyN-1 elements into the new (smaller) frozenset object.  So this isn't anargument.> 2) if I have to keep the old copy,>     standard set solution will be O(n) both in time and space!>Again, nothing gained here. Same applies to frozenset.pop() (assuming itreturns both the item popped and a reduced set).  If you just want"something from frozenset" without creating a new almost-copy frozenset,that is spelled `next(iter(fs))`.> working examples:>     1) priority queue:>         insert and pop occur>     2) share immutable data to difference subroutines:>         each one can modify local copy safely and concurrency.>Sounds like `collections.deque` might be what you want (for concurrency,not for immutability).  But a local copy will require, by definition, a*copy* operation either way.-- Keeping medicines from the bloodstreams of the sick; foodfrom the bellies of the hungry; books from the hands of theuneducated; technology from the underdeveloped; and puttingadvocates of freedom in prisons.  Intellectual property isto the 21st century what the slave trade was to the 16th.-------------- next part --------------An HTML attachment was scrubbed...URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170228/68e22da6/attachment.html>


More information about the Python-ideasmailing list

[8]ページ先頭

©2009-2026 Movatter.jp