Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'mrab': 0.05; 'duplicate': 0.07; 'plenty': 0.07; 'dan': 0.09; 'iterate': 0.09; 'subject:using': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'dict': 0.16; 'dictionary,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'tuple.': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'skip:g 30': 0.30; 'message- id:@mail.gmail.com': 0.30; 'int,': 0.31; 'safely': 0.31; 'sep': 0.31; 'this.': 0.32; 'fri,': 0.33; 'skip:d 20': 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'easily': 0.37; 'pm,': 0.38; 'bad': 0.39; 'use.': 0.39; 'direct': 0.67; "'foo'": 0.84; 'calm': 0.84; 'dict()': 0.84; 'float,': 0.84; 'yes!': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=qHtD9i4QKCSIlYpC274CWLOdUKsdHx6rvPFhza4HOHA=; b=A+2jb1jsOkXkarc2+tmdRwOt6SWxEJ+3v0G9lxPwiQtRX/T0j8IegACapjM23XRzb1 rKjvaKfWzbwUHD3udUez9U1ia/nPgCe4mXI1rFUFW4YTR6p0RFOgdg5ei7uT6S+bbAet wHdDXwDOVh3k+gJIFWAKaPJXN8nIF40rOVuf5zGMM5ZQlxY5ZT/ZPmTJ1JVlAr00RoQT u90KaXPWNabd1cDy7LW0UdOs9hildTWvzerc9GuaNiVgOlcaKIG6g+/trpMmCz33me+b oZ9biJZ0Z66tg0j90U1Bt7FMR7I9bu/VkAkJoPY5KPP7RHeTirrO14CZj0PMfUfPxEVr c+5Q== MIME-Version: 1.0 X-Received: by 10.42.118.211 with SMTP id y19mr11436015icq.12.1409893689484; Thu, 04 Sep 2014 22:08:09 -0700 (PDT) In-Reply-To: References: <46e782a5-b087-4f95-aadb-26e233bf5419@googlegroups.com> <5407A69B.3030707@mrabarnett.plus.com> Date: Fri, 5 Sep 2014 15:08:09 +1000 Subject: Re: Storing instances using jsonpickle From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1409893692 news.xs4all.nl 2940 [2001:888:2000:d::a6]:58644 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77576 On Fri, Sep 5, 2014 at 2:38 PM, Dan Sommers wrote: > On Thu, 04 Sep 2014 15:17:17 +1000, Chris Angelico wrote: > >> On Thu, Sep 4, 2014 at 9:39 AM, MRAB wrote: > >>> The key of a dict could also be int, float, or tuple. >> >> Yes! Yes! DEFINITELY do this!! Ahem. Calm down a little, it's not that >> outlandish an idea... > > Using floats is a bad idea. Consider this python code: > > dictionary = dict() > original = get_some_floating_point_value() > dictionary[original] = 'foo' > string_version = str(original) # this is where things head south > duplicate = float(string_version) > value = dictionary.get(duplicate) > > Okay, so what is value? Is it 'foo'? Is it None? > > (Yes, I can fix this. If I *know* that original is a float, then I > could use original.hex() instead of str(original).) There are issues with direct lookups, yes, but you can safely and easily iterate over that dictionary, and that's going to have plenty of use. ChrisA