Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #15600

Re: Get keys from a dicionary

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'string.': 0.04; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'subject:keys': 0.09; 'def': 0.14; 'folks': 0.15; 'ideally': 0.15; "'a'": 0.16; "'and": 0.16; 'wrote:': 0.18; 'knowing': 0.23; 'dictionary': 0.23; 'header:In-Reply-To:1': 0.23; 'guess': 0.25; "i'm": 0.26; 'pass': 0.28; 'work:': 0.28; 'problem': 0.29; 'print': 0.29; 'do.': 0.30; 'standalone': 0.30; 'example': 0.30; 'pm,': 0.31; 'to:addr:python-list': 0.32; 'it.': 0.33; 'there': 0.33; 'header:User-Agent:1': 0.33; 'header:X-Complaints-To:1': 0.33; 'done.': 0.34; 'loop': 0.34; 'function.': 0.34; 'nested': 0.34; 'something': 0.36; 'doing': 0.37; 'think': 0.37; 'received:org': 0.37; 'question,': 0.38; 'some': 0.38; 'perhaps': 0.38; 'help': 0.39; 'why': 0.39; 'subject:: ': 0.39; 'might': 0.39; 'to:addr:python.org': 0.39; 'really': 0.40; 'more': 0.60; 'your': 0.61; 'below': 0.63; 'subject:Get': 0.71; 'different.': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Gelonida N <gelonida@gmail.com>
Subject Re: Get keys from a dicionary
Date Fri, 11 Nov 2011 18:29:59 +0100
References <8f5215a8-d08f-4355-a5a2-77fcaa32c92d@j10g2000vbe.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host unicorn.dungeon.de
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110921 Lightning/1.0b2 ""
In-Reply-To <8f5215a8-d08f-4355-a5a2-77fcaa32c92d@j10g2000vbe.googlegroups.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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2650.1321032617.27778.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1321032617 news.xs4all.nl 6859 [2001:888:2000:d::a6]:54023
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:15600

Show key headers only | View raw


On 11/11/2011 02:31 PM, macm wrote:
> Hi Folks
> 
> I pass a nested dictionary to a function.
> 
> def Dicty( dict[k1][k2] ):
> 	print k1
> 	print k2
> 
> There is a fast way (trick) to get k1 and k2 as string.
> 
> Whithout loop all dict. Just it!
> 
> Regards
> 
> macm


I think the answer to the question, that I don't really understand is:
No. This cannot be done.


However we might help you if you copy a COMPLETE standalone example of
your problem and if you try to re-explain once more what exactly you
want to do.

Ideally tell us even why you want to do it. Perhaps the solution is
something completely different.


Below I'm doing some guess work:


nesteddict = { 'a': { 'A' : 'value1 a_A' , 'B' : 'value2 a_B' },
               'b': { 'A' : 'value3 b_A' , 'B' : 'value4 b_B' },
               'c': { 'A' : 'value3 b_A' , 'B' : 'value4 b_B' },
             }

def mymagic_function(value):
   print 'the value is <%s>', value
   print('There is really no way knowing from where this value came\n'
        'except if you tell me in which dictionary you are supposed\n'
         'and if I just try to find all matches\n' )

value = nesteddict['a']['B']

mymagic_function(value)


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 05:31 -0800
  Re: Get keys from a dicionary Jon Clements <joncle@googlemail.com> - 2011-11-11 08:09 -0800
    Re: Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 08:33 -0800
      Re: Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 08:38 -0800
      Re: Get keys from a dicionary Dave Angel <d@davea.name> - 2011-11-11 11:47 -0500
      Re: Get keys from a dicionary John Gordon <gordon@panix.com> - 2011-11-11 17:28 +0000
  Re: Get keys from a dicionary John Gordon <gordon@panix.com> - 2011-11-11 16:25 +0000
    Re: Get keys from a dicionary macm <moura.mario@gmail.com> - 2011-11-11 08:36 -0800
  Re: Get keys from a dicionary Gelonida N <gelonida@gmail.com> - 2011-11-11 18:29 +0100
  Re: Get keys from a dicionary Gelonida N <gelonida@gmail.com> - 2011-11-11 18:45 +0100
    Re: Get keys from a dicionary John Gordon <gordon@panix.com> - 2011-11-11 17:51 +0000
  Re: Get keys from a dicionary alex23 <wuwei23@gmail.com> - 2011-11-13 21:42 -0800
  Re: Get keys from a dicionary alex23 <wuwei23@gmail.com> - 2011-11-13 21:44 -0800
  Multilevel dicts/arrays v. tuples as keys? [Was: Re: Get keys from a dicionary] Matej Cepl <mcepl@redhat.com> - 2011-11-14 11:05 +0100
    Re: Multilevel dicts/arrays v. tuples as keys? [Was: Re: Get keys from a dicionary] Tim Golden <mail@timgolden.me.uk> - 2011-11-14 10:42 +0000
    Re: Multilevel dicts/arrays v. tuples as keys? Peter Otten <__peter__@web.de> - 2011-11-14 11:47 +0100
      Re: Multilevel dicts/arrays v. tuples as keys? alex23 <wuwei23@gmail.com> - 2011-11-14 19:07 -0800

csiph-web