Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!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; 'subject:file': 0.07; 'brackets': 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; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message-id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'semicolon': 0.16; 'wrote:': 0.17; 'appropriate': 0.20; 'cc:2**1': 0.24; '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; 'this?': 0.28; 'file': 0.32; 'print': 0.32; 'something': 0.35; 'cc:no real name:2**1': 0.36; 'subject:: ': 0.38; 'more': 0.63; 'making': 0.64; 'received:50.22': 0.84 Date: Thu, 09 Aug 2012 15:35:32 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 MIME-Version: 1.0 To: Roman Vashkevich Subject: Re: save dictionary to a file without brackets. References: <930ab3d8-4ab9-446d-9970-ee811eb70a44@googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Source: X-Source-Args: X-Source-Dir: 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1344544469 news.xs4all.nl 6891 [2001:888:2000:d::a6]:36850 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26808 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 > > for key in dict: > print key[0], key[1], dict[key] This might read more cleanly with tuple unpacking: for (edge1, edge2), cost in d.iteritems(): # or .items() print edge1, edge2, cost (I'm making the assumption that this is a edge/cost graph...use appropriate names according to what they actually mean) -tkc