Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Question about math.pi is mutable Date: Sun, 8 Nov 2015 23:28:00 +1100 Lines: 17 Message-ID: References: <87d1vlzy4p.fsf@elektro.pacujo.net> <878u69zxww.fsf@elektro.pacujo.net> <563eba85$0$1611$c3e8da3$5496439d@news.astraweb.com> <87ziyowy83.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de jwCMrXk020QagfXNZewzqgXNS9QKLPMA1SkI5b2kQihA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'subject:Question': 0.05; 'cc:addr:python-list': 0.09; 'literal': 0.09; 'lookup': 0.09; 'python.': 0.11; 'things.': 0.15; "(i'm": 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hashes': 0.16; 'operation,': 0.16; 'reason).': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'looked': 0.16; 'module,': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'assuming': 0.22; 'constant': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; 'sort': 0.25; "i've": 0.25; 'message-id:@mail.gmail.com': 0.27; 'specifically': 0.28; 'dictionary': 0.29; 'structure,': 0.29; 'common': 0.33; 'similar': 0.33; 'case,': 0.34; 'received:google.com': 0.35; 'text': 0.35; 'nov': 0.35; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'names': 0.38; 'why': 0.39; 'data': 0.39; 'where': 0.40; 'still': 0.40; 'some': 0.40; 'your': 0.60; 'virtually': 0.66; 'overall': 0.72; 'chrisa': 0.84; 'stored,': 0.84; 'to:none': 0.91 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=tMHOb2Moj5fdr+Z0wvIeMmJ/Pt5UkXOnpXb9nESH0uU=; b=0Znv3giMJ2TKLQm/KWgBsuwTVUsSCM9J82tPM9Ka0P7rJRA1y6ke4BDXlf3a8q9A1k EktuB/BNDkgpKxgeHYKKPy5+FKsyHdi/A2yZkEa/IaQFCPm9CELoVkbmyDQ1cmYDWlZu pAUeOLtVTBFoAMPtvAqd/TMNi5wg4GXSIejqjYQKPaD7JUQcRYdbcQgxBN8btz2wIYpA fW6LFv7aI7gOYlC2tKJkyRJRj/ZvkqUNU2XyxEFSdIC1ejxVw/CpgsAN1If/MPA+QKxa vieF/dU4nhBKMxs0LkiyPImME1mxHOrArC62hDAXFGXrYfGlNmgf1UDyRyBbNQDQD6Nc NAtQ== X-Received: by 10.50.56.70 with SMTP id y6mr4572750igp.13.1446985681048; Sun, 08 Nov 2015 04:28:01 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98447 On Sun, Nov 8, 2015 at 10:19 PM, BartC wrote: > I've never understood why this seems to be necessary in Python. Why do names > have to be looked up? (I'm assuming this is searching by name in some sort > of table.) Yes, if by "searching" you include hash-table lookup. A CPython dictionary is a *highly* optimized data structure, specifically because it's used virtually everywhere (I understand Lua's "table" type has similar optimizations for the same reason). In the common case, where your names come from literal text in the module, the strings used for the lookup will be interned constants, and their hashes will have been precalculated and stored, so the lookup is pretty easy. So it's a constant-time operation, and while that constant may be larger than a simple offset-and-fetch, it's still pretty fast in the overall scheme of things. ChrisA