Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.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.020 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'algorithm': 0.03; 'subject:file': 0.07; 'dict': 0.09; 'sure,': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'read.': 0.13; 'entries,': 0.16; 'hashed': 0.16; 'wrote:': 0.17; 'saying': 0.18; 'latter': 0.22; 'lets': 0.22; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'cc:addr:gmail.com': 0.27; 'order.': 0.27; 'cc:2**2': 0.27; 'first.': 0.27; 'hash': 0.29; 'key,': 0.29; 'probably': 0.29; 'figure': 0.30; 'print': 0.32; 'another': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'faster': 0.35; 'from:addr:googlemail.com': 0.35; 'so,': 0.35; 'pm,': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; "i'll": 0.36; 'ok,': 0.37; 'uses': 0.37; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'store': 0.38; 'easier': 0.38; 'harder': 0.65; 'actually,': 0.84; 'difference.': 0.84; 'different.': 0.84; 'cc:no real name:2**2': 0.91; 'received:209.85.220.184': 0.91; 'hundred': 0.95 Newsgroups: comp.lang.python Date: Fri, 10 Aug 2012 10:46:09 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=123.192.83.145; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw 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> <583C055C-9E99-4EAC-8F3A-D578C399826E@gmail.com> User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 123.192.83.145 MIME-Version: 1.0 Subject: Re: save dictionary to a file without brackets. From: 88888 Dihedral To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: d@davea.name, giuseppe.amatulli@gmail.com, python-list@python.org 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: , Message-ID: Lines: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344620771 news.xs4all.nl 6907 [2001:888:2000:d::a6]:40856 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26884 Dave Angel=E6=96=BC 2012=E5=B9=B48=E6=9C=8810=E6=97=A5=E6=98=9F=E6=9C=9F=E4= =BA=94UTC+8=E4=B8=8A=E5=8D=885=E6=99=8247=E5=88=8645=E7=A7=92=E5=AF=AB=E9= =81=93=EF=BC=9A > On 08/09/2012 05:34 PM, Roman Vashkevich wrote: >=20 > > Actually, they are different. >=20 > > Put a dict.{iter}items() in an O(k^N) algorithm and make it a hundred t= housand entries, and you will feel the difference. >=20 > > Dict uses hashing to get a value from the dict and this is why it's O(1= ). >=20 >=20 >=20 > Sure, that's why >=20 >=20 >=20 > for key in dict: >=20 > print key[0], key[1], dict[key] >=20 >=20 >=20 > is probably slower than >=20 >=20 >=20 > for (edge1, edge2), cost in d.iteritems(): # or .items() >=20 > print edge1, edge2, cost >=20 >=20 >=20 >=20 >=20 > So, the latter is both faster and easier to read. Why are you arguing ag= ainst it? >=20 >=20 >=20 > Also, please stop top-posting. It's impolite here, and makes it much har= der to figure out who is saying what, in what order. >=20 >=20 >=20 >=20 >=20 >=20 >=20 > --=20 >=20 >=20 >=20 > DaveA OK, lets estimate the hash colision rate first. For those items hashed to the same key, I'll store a sorted list with a known lenth m to be accessed in O(LOG(M)).=20 Of couse another hash can be attatched.