Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #109811
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: fast dictionary initialization |
| Date | Fri, 10 Jun 2016 18:20:14 -0500 |
| Lines | 32 |
| Message-ID | <mailman.148.1465613257.2306.python-list@python.org> (permalink) |
| References | <d2ee0910-1635-431e-944c-c8b4167f10c5@googlegroups.com> <20160610182014.0a9182a9@bigbox.christie.dr> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=US-ASCII |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de Sg74eY2RjElXJ+N/rGmlBQ2U/r48wQUhwm6wSz4sOUkQ== |
| 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.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'dict': 0.09; 'example:': 0.10; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'received:10.104': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'silly': 0.16; 'storing': 0.16; 'wrote:': 0.16; 'translation': 0.16; 'string': 0.17; 'basically': 0.18; 'subject:skip:i 10': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.24; 'function': 0.28; 'idea': 0.28; 'dictionary': 0.29; 'convert': 0.29; 'skip:[ 10': 0.31; 'similar': 0.33; 'mapping': 0.35; 'options:': 0.35; 'instead': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'charset:us-ascii': 0.37; 'to:addr:python.org': 0.40; 'where': 0.40; 'your': 0.60; 'worth': 0.67; 'received:23': 0.84 |
| X-Sender-Id | wwwh|x-authuser|tim@thechases.com |
| X-Sender-Id | wwwh|x-authuser|tim@thechases.com |
| X-MC-Relay | Neutral |
| X-MailChannels-SenderId | wwwh|x-authuser|tim@thechases.com |
| X-MailChannels-Auth-Id | wwwh |
| X-MC-Loop-Signature | 1465600816357:3103138998 |
| X-MC-Ingress-Time | 1465600816357 |
| In-Reply-To | <d2ee0910-1635-431e-944c-c8b4167f10c5@googlegroups.com> |
| X-Mailer | Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) |
| X-AuthUser | tim@thechases.com |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| 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> |
| X-Mailman-Original-Message-ID | <20160610182014.0a9182a9@bigbox.christie.dr> |
| X-Mailman-Original-References | <d2ee0910-1635-431e-944c-c8b4167f10c5@googlegroups.com> |
| Xref | csiph.com comp.lang.python:109811 |
Show key headers only | View raw
On 2016-06-10 14:07, maurice wrote:
> example:
> valuesList = [1,2,3]
> keysList = ['1','2','3']
>
> So the dictionary can basically convert string to int:
>
> dictionary = {'1':1, '2':2, '3':3}
A couple similar options:
The most straightforward translation of your description:
opt1 = dict(zip(keysList, valuesList))
print(opt1["2"])
And one where you generate the strings on the fly:
opt2 = dict((str(i), i) for i in range(1, 4))
print(opt2["2"])
And one where you use the int() function instead of a mapping because
the whole idea of storing a dict worth of string-numbers-to-numbers
seems somewhat silly to me:
print(int("2"))
-tkc
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
fast dictionary initialization maurice <mauricioliveiraguarda@gmail.com> - 2016-06-10 14:07 -0700 Re: fast dictionary initialization Random832 <random832@fastmail.com> - 2016-06-10 17:15 -0400 Re: fast dictionary initialization Tim Chase <python.list@tim.thechases.com> - 2016-06-10 18:20 -0500
csiph-web