Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'linear': 0.07; 'subject:file': 0.07; 'url:pycon': 0.07; 'brackets': 0.09; 'received:mail-lpp01m010-f46.google.com': 0.09; 'to:addr:python.list': 0.09; 'to:addr:tim.thechases.com': 0.09; 'to:name:tim chase': 0.09; 'tuple': 0.09; 'cc:addr:python-list': 0.10; '(2,': 0.16; "(i'm": 0.16; '-tkc': 0.16; '3):': 0.16; 'cleanly': 0.16; 'semicolon': 0.16; 'wrote:': 0.17; 'tim': 0.18; '>>>': 0.18; 'appropriate': 0.20; 'x-mailer:apple mail (2.1084)': 0.22; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'cc:addr:gmail.com': 0.27; 'this?': 0.28; 'chase': 0.29; 'received:209.85.215.46': 0.30; 'url:python': 0.32; 'file': 0.32; 'print': 0.32; 'received:google.com': 0.34; 'list': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'message- id:@gmail.com': 0.36; 'cc:no real name:2**1': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'header:Received:5': 0.40; 'header:Message-Id:1': 0.62; 'more': 0.63; 'making': 0.64; 'received:ru': 0.81; 'url:2007': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=aFrGVh/hmB+XVwuAD6vpDqAOUsFR4CGgvDbf6ovhicA=; b=yvrAu793+QoPHv3A1PS3vVMqCjSyP6MWUa2yHWGdGI3dFjSLh5QC2z/s0tDD8l1soX 3gbQDwbLKk3vxIlmV94RZFtBoLAcjzVIAHLbSIvatKOv42Q8ZtcYU7zoNmP+86mGD1Kl N57DzUiIdHBBX3zayws00NdkoQjwoEBv4aahDxvMLCn436fuSSRR/LwqArFCp9+VZtqf lPSFtFAB2gRzj2chQlBgBqofAG3L4lAcIiz5KJoT1qN8mh1n380WFAYaP59FGcYUz0Gf G2B0jmchDKkcuO0pRc7UTL7ohXhv5AvbCiZqjmeE8Oj/fYOX4wz6bxnzbP9+Oi5yZQ0v PJ5A== Subject: Re: save dictionary to a file without brackets. Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=koi8-r From: Roman Vashkevich In-Reply-To: <50241F14.2060209@tim.thechases.com> Date: Fri, 10 Aug 2012 00:41:32 +0400 Content-Transfer-Encoding: quoted-printable References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> <50241F14.2060209@tim.thechases.com> To: Tim Chase X-Mailer: Apple Mail (2.1084) Cc: python-list@python.org, giuseppe.amatulli@gmail.com 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344544898 news.xs4all.nl 6847 [2001:888:2000:d::a6]:45176 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26812 dict.items() is a list - linear access time whereas with 'for key in = dict:' access time is constant: = http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#use-= in-where-possible-1 10.08.2012, =D7 0:35, Tim Chase =CE=C1=D0=C9=D3=C1=CC(=C1): > On 08/09/12 15:22, Roman Vashkevich wrote: >>> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2} >>> and i want to print to a file without the brackets comas and = semicolon in order to obtain something like this? >>> 4 5 1 >>> 5 4 1 >>> 4 4 2 >>> 2 3 1 >>> 4 3 2 >>=20 >> for key in dict: >> print key[0], key[1], dict[key] >=20 > This might read more cleanly with tuple unpacking: >=20 > for (edge1, edge2), cost in d.iteritems(): # or .items() > print edge1, edge2, cost >=20 > (I'm making the assumption that this is a edge/cost graph...use > appropriate names according to what they actually mean) >=20 > -tkc >=20 >=20 >=20