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


Groups > comp.lang.python > #64617

Re: Initialise dictionary of dictionary

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.010
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'defaults': 0.07; 'float': 0.07; 'python': 0.11; '-tkc': 0.16; 'collections': 0.16; 'defaultdict': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:In-Reply-To:1': 0.27; 'values.': 0.31; 'really': 0.36; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'received:50.22': 0.84
Date Thu, 23 Jan 2014 09:30:23 -0600
From Tim Chase <python.list@tim.thechases.com>
To python-list@python.org
Subject Re: Initialise dictionary of dictionary
In-Reply-To <f2f630c9-434c-43c1-bd80-4fadcc552e0a@googlegroups.com>
References <f2f630c9-434c-43c1-bd80-4fadcc552e0a@googlegroups.com>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-OutGoing-Spam-Status No, score=-1.5
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-Get-Message-Sender-Via boston.accountservergroup.com: authenticated_id: tim@thechases.com
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5894.1390490976.18130.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1390490976 news.xs4all.nl 2867 [2001:888:2000:d::a6]:38577
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64617

Show key headers only | View raw


On 2014-01-23 07:15, Ayushi Dalmia wrote:
> I need to initialise a dictionary of dictionary with float values.
> I do not know the size of the dictionary beforehand. How can we do
> that in Python --
 
Either

  d = {}

or, if you want

  from collections import defaultdict
  d = defaultdict(float)
  print(d["Hello"])

If you really do want a dict-of-dict that defaults to floats, you can
do

  d = defaultdict(lambda: defaultdict(float))
  print(d[3141]["Hello"])

-tkc


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


Thread

Initialise dictionary of dictionary Ayushi Dalmia <ayushidalmia2604@gmail.com> - 2014-01-23 07:15 -0800
  Re: Initialise dictionary of dictionary Tim Chase <python.list@tim.thechases.com> - 2014-01-23 09:30 -0600
    Re: Initialise dictionary of dictionary Ayushi Dalmia <ayushidalmia2604@gmail.com> - 2014-01-23 21:42 -0800
  Re:Initialise dictionary of dictionary Dave Angel <davea@davea.name> - 2014-01-23 10:34 -0500
  Re: Initialise dictionary of dictionary Tim Chase <python.list@tim.thechases.com> - 2014-01-23 09:41 -0600

csiph-web