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


Groups > comp.lang.python > #6657

Re: searching in list

Date 2011-05-30 09:27 -0400
From Dave Angel <davea@ieee.org>
Subject Re: searching in list
References <cec1aa77-86b3-4bff-8286-a84c823750d2@glegroupsg2000goo.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.2264.1306762089.9059.python-list@python.org> (permalink)

Show all headers | View raw


On 01/-10/-28163 02:59 PM, vino19 wrote:
> I want to make a function that is called only once per one argument. I mean I want to store data of function calling to prevent calling it again if there is no need.
> How to make it? For example I can make a global list that just consist of tuples
> [(arg1, res1), (arg2, res2), ...]. Ok, how to search if an arg135 in that list?
>
> Thanks for answering
>

Usual answer is to use a dict.  You can convert a list of tuples to a 
dict by    dict(mylist)

Second choice is to keep the list sorted, and use the bisect module. 
But usually a dictionary is better.

DaveA

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


Thread

searching in list vino19 <vinograd19@gmail.com> - 2011-05-30 05:58 -0700
  Re: searching in list Dave Angel <davea@ieee.org> - 2011-05-30 09:27 -0400
  Re: searching in list Chris Angelico <rosuav@gmail.com> - 2011-05-30 23:41 +1000
  Re: searching in list Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-30 10:32 -0600

csiph-web