Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'algorithm': 0.03; 'true,': 0.04; 'cpython': 0.05; 'method.': 0.05; 'plenty': 0.07; 'subject:file': 0.07; 'dict': 0.09; 'lookup': 0.09; 'received :mail-vc0-f174.google.com': 0.09; 'def': 0.10; 'aug': 0.13; 'datasets.': 0.16; 'dictionaries': 0.16; 'efficiency.': 0.16; 'entries,': 0.16; 'entry.': 0.16; 'lookups.': 0.16; 'pathological': 0.16; 'wrote:': 0.17; 'thu,': 0.17; '>>>': 0.18; 'constant': 0.22; 'header:In-Reply-To:1': 0.25; 'common': 0.26; 'values': 0.26; 'andrew': 0.27; 'entries': 0.27; 'message- id:@mail.gmail.com': 0.27; 'dictionary': 0.29; 'hash': 0.29; 'received:209.85.220.174': 0.29; 'sensible': 0.29; 'url:mailman': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; "i'm": 0.29; 'becomes': 0.30; 'function': 0.30; '(and': 0.32; 'url:python': 0.32; 'url:listinfo': 0.32; 'cases,': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; 'received:google.com': 0.34; 'self': 0.34; 'wrong': 0.34; 'pm,': 0.35; 'received:209.85.220': 0.35; 'table': 0.35; 'similar': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'url:org': 0.36; 'too': 0.36; 'uses': 0.37; 'why': 0.37; 'received:209': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'url:mail': 0.40; 'behavior': 0.64; 'equals': 0.65; 'topic,': 0.78; 'actually,': 0.84; 'collision': 0.84; 'difference.': 0.84; 'different.': 0.84; 'glad': 0.86; 'increases': 0.91; 'sensibly': 0.91; 'suffer': 0.91; 'angel': 0.93; 'poorly': 0.93; 'hundred': 0.95 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:x-gm-message-state; bh=mYYM5d2oFKbHvmGxiNQEMF2tIDnZbL01jSayRVhQl9k=; b=gD4yUqtJ8Rn72UHV3M/Gh04/zkbWFvU74A2ap+TnsMzKpj/MRcI+sJZY7AAFsOD6Df NvXu1/i+6f9Wub7xhPkyrGDsJFWdkKMIyz7yIpmF16tIErJ8fuS4XMO7UTRQzv7E6AJN MArPJegpUWvPHyWO+Ene539g/P2qGOU+q6Jbjbw/s4xkOioREXCsyuQhqiW4RZ7WLZpB VIglZdC41Er/Dn/z5MLnTmTVUxP3TusgWo3pdIi5u9/TQZLCGz9oV11vNE9/ai/LxHPd Ooz/Me6hwoFKZeKPSAD+nqoZBFfFGGwBgxLY6Rjrsd+5GnzKUVA14whKg9G+ALkqTU8P qYJQ== MIME-Version: 1.0 In-Reply-To: <5024392D.3010306@davea.name> References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> <36EA3847-6713-4C12-B47B-9B5E10325F00@gmail.com> <502429C3.5000600@tim.thechases.com> <5024392D.3010306@davea.name> From: Chris Kaynor Date: Thu, 9 Aug 2012 15:37:59 -0700 Subject: Re: save dictionary to a file without brackets. To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQmG/waLSwOZ/v052MjlRcg/gqUxn0M9go6PUJc3ZejqNhO2puBHkSsWcSw7ba0lGzSzIW9o X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344551903 news.xs4all.nl 6852 [2001:888:2000:d::a6]:52631 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26827 On Thu, Aug 9, 2012 at 3:26 PM, Dave Angel wrote: > On 08/09/2012 06:03 PM, Andrew Cooper wrote: >> On 09/08/2012 22:34, Roman Vashkevich wrote: >>> Actually, they are different. >>> Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred thousand entries, and you will feel the difference. >>> Dict uses hashing to get a value from the dict and this is why it's O(1). >>> >> Sligtly off topic, but looking up a value in a dictionary is actually >> O(n) for all other entries in the dict which suffer a hash collision >> with the searched entry. >> >> True, a sensible choice of hash function will reduce n to 1 in common >> cases, but it becomes an important consideration for larger datasets. >> >> ~Andrew > > I'm glad you're wrong for CPython's dictionaries. The only time the > lookup would degenerate to O[n] would be if the hash table had only one > slot. CPython sensibly increases the hash table size when it becomes > too small for efficiency. > > > Where have you seen dictionaries so poorly implemented? There are plenty of ways to make a pathological hash function that will have that issue in CPython. The very simple (and stupid): class O(object): def __hash__(self): return 0 def __eq__(self, other): # I am aware this is the default equals method. return self is other Start adding those to a dictionary to get O(n) lookups. Any case the hash return values modulus the dictionary hash table size is constant will have similar results; powers of 2 are likely to result in such behavior as well. > > -- > > DaveA > > -- > http://mail.python.org/mailman/listinfo/python-list