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


Groups > comp.lang.python > #109799

Re: fast dictionary initialization

From Random832 <random832@fastmail.com>
Newsgroups comp.lang.python
Subject Re: fast dictionary initialization
Date 2016-06-10 17:15 -0400
Message-ID <mailman.142.1465593350.2306.python-list@python.org> (permalink)
References <d2ee0910-1635-431e-944c-c8b4167f10c5@googlegroups.com> <1465593346.2349149.634242025.11CE5139@webmail.messagingengine.com>

Show all headers | View raw


pOn Fri, Jun 10, 2016, at 17:07, maurice wrote:
> Hi. If I have already a list of values, let's call it valuesList and the
> keysList, both same sized lists, what is the easiest/quickest way to
> initialize a dictionary with those keys and list, in terms of number of
> lines perhaps?
> 
> 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}

dict(zip(keysList, valuesList))

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


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