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


Groups > comp.lang.python > #6657

Re: searching in list

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <SRS0=RZMK=YU=ieee.org=davea@srs.perfora.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.025
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'dictionary': 0.07; 'answering': 0.09; 'dict': 0.09; 'pm,': 0.10; 'wrote:': 0.14; 'sorted,': 0.16; 'list?': 0.16; 'cc:addr:python-list': 0.17; 'subject:list': 0.19; 'convert': 0.19; 'header:In-Reply-To:1': 0.21; 'cc:no real name:2**0': 0.23; 'function': 0.25; 'example': 0.27; 'thanks': 0.28; 'consist': 0.29; 'cc:addr:python.org': 0.30; 'second': 0.30; 'cc:addr:gmail.com': 0.30; 'tuples': 0.30; 'calling': 0.31; 'usually': 0.32; 'list': 0.33; 'it?': 0.33; 'there': 0.35; 'header:User-Agent:1': 0.35; 'module.': 0.35; 'store': 0.35; 'usual': 0.35; 'cc:2**1': 0.35; 'but': 0.38; 'data': 0.38; 'ok,': 0.38; 'subject:: ': 0.38; 'received:192': 0.38; 'called': 0.39; 'received:192.168.1': 0.40; 'header:Reply- To:1': 0.72; 'reply-to:no real name:2**0': 0.72; '02:59': 0.84; 'to:none': 0.93
Date Mon, 30 May 2011 09:27:33 -0400
From Dave Angel <davea@ieee.org>
User-Agent Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10
MIME-Version 1.0
Subject Re: searching in list
References <cec1aa77-86b3-4bff-8286-a84c823750d2@glegroupsg2000goo.googlegroups.com>
In-Reply-To <cec1aa77-86b3-4bff-8286-a84c823750d2@glegroupsg2000goo.googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:ANVgMnjBx58tYaSkC/I5rsnxOm80C6mpVi/YHJKVSbB oaav32F08SJlpsj/4zZLOU2OLfG9xDg55m+SPYF0/1jVWn8X5Z f048O9cYFdiXommsKDBPfJK4EEJ+O7yxh9LVJl6rGmPsYrI9ZN Ts6NpZHxjKWGJKRVSCbefGsFZmmDHW/9Ekbo754mIJ3JODugzn k8lofY3w1UdnCjCihNLmQ==
Cc python-list@python.org, vino19 <vinograd19@gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To davea@ieee.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2264.1306762089.9059.python-list@python.org> (permalink)
Lines 15
NNTP-Posting-Host 82.94.164.166
X-Trace 1306762090 news.xs4all.nl 49184 [::ffff:82.94.164.166]:49909
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6657

Show key headers only | 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