Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.029 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'function:': 0.09; 'iterate': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'suggest': 0.14; 'dict': 0.16; 'function()': 0.16; 'iterated': 0.16; 'iterkeys': 0.16; 'prog': 0.16; 'subject: ?': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'helpful': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'header:In- Reply-To:1': 0.27; 'function': 0.29; 'returned': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'probably': 0.32; 'sense': 0.34; 'received:209.85': 0.35; 'problem.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'shows': 0.36; 'possible': 0.36; 'url:org': 0.36; 'error.': 0.37; 'received:209': 0.37; 'subject:Can': 0.60; 'here:': 0.62; 'address': 0.63; 'more': 0.64; 'to:addr:gmail.com': 0.65; 'oscar': 0.84; 'subject:over': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=f0i3yxLDPCzmXgUS6FGl0AejQdo/FEwNxfTbiJ+PH4E=; b=p4N7OqIZeqNLizcImG3HJ91Hje9M97kITOH9THbgGHCFYR0P9J1yoKDJFEnXZOijve BmBncOwgT6S8iwUTITYIvcBXoItUGgd1KncGbkvk84Z0sfpS3dxmN6t2EXdneO9pgYOj sS/aTiIqunX6GtQt1OhGWf1ryDag1X9f6VLtQ3DdLjcvbTXDNFCL+lv215qGv1NoRmfO DsidbY1KzWw5bBg2/+5OjMZPCEIYka3MNg6GD/k/Z+6wYP3NSGYeslx4gavTjk1qtOEi 0/Z3Z5wIDVeieTKdec8KCyhdtWa2N6OaWnQ0BNbeypERM/J8VSwJr6Y/7X9L9I2/GXcT WJFg== X-Received: by 10.52.71.235 with SMTP id y11mr3694424vdu.43.1365674354809; Thu, 11 Apr 2013 02:59:14 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Oscar Benjamin Date: Thu, 11 Apr 2013 10:58:54 +0100 Subject: Re: Can I iterate over a dictionary outside a function ? To: inshu chauhan Content-Type: text/plain; charset=ISO-8859-1 Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1365674357 news.xs4all.nl 2563 [2001:888:2000:d::a6]:59418 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43345 On 11 April 2013 10:48, inshu chauhan wrote: > I have a prog in which a functions returns a dict but when I try to iterate > over the dict using iterkeys, It shows an error. I think its because only > address of the dictionary is returned so cannot be iterated upon. > > Please suggest some way by which it can be made possible to iterate over the > dictionary using iterkeys outside the function ? You would probably get a more helpful answer if you showed the code that is giving you a problem. See here: http://sscce.org/ Your question makes no sense to me. It is perfectly possible to iterate over a dict returned from a function: >>> def function(): ... d = {'asd':123, 'qwe': 456} ... return d ... >>> a = function() >>> a {'qwe': 456, 'asd': 123} >>> for x in a.iterkeys(): ... print(x) ... qwe asd Oscar