Re: [Tutor] dictionaries help

2009-07-24 Thread Kent Johnson
On Fri, Jul 24, 2009 at 3:01 AM, wrote: >> If ws_industry contains 25 items, it will probably be faster to search >> it if it is a set rather than a list. Just use >> ws_industry = set(('it', 'science')) > > ws_industry contains only unique values OK. It will still be faster to check membership i

Re: [Tutor] dictionaries help

2009-07-24 Thread davidwilson
Hello Original Message From: Kent Johnson Apparently from: kent3...@gmail.com To: davidwil...@safe-mail.net Cc: tutor@python.org Subject: Re: [Tutor] dictionaries help Date: Thu, 23 Jul 2009 21:44:33 -0400 > On Thu, Jul 23, 2009 at 7:09 PM, wrote: > > Hello again, &g

Re: [Tutor] dictionaries help

2009-07-23 Thread Kent Johnson
On Thu, Jul 23, 2009 at 7:09 PM, wrote: > Hello again, > Here is my full attempt, can you please tell me if it is OK and if there > should be any improvements >     ws_industry = ('it', 'science') code = ws_industry[0] active = [] industries = [{'code': 'it', 'name': 'Informat

Re: [Tutor] dictionaries help

2009-07-23 Thread davidwilson
more efficient. Basically I have a big list of industries and I want to verify for each member whether they are active or not active. The industry list of dictionaries will stay fixed at about 25 items, whereas the ws_industry tuple will change depending. I have to go through about 20,000 item

Re: [Tutor] dictionaries help

2009-07-23 Thread davidwilson
thank you for all your answers Original Message From: Norman Khine Apparently from: tutor-bounces+davidwilson=safe-mail@python.org To: tutor@python.org Subject: Re: [Tutor] dictionaries help Date: Thu, 23 Jul 2009 21:59:01 +0100 > Also you can use list comprehens

Re: [Tutor] dictionaries help

2009-07-23 Thread Norman Khine
Also you can use list comprehension In [1]: my_lst = [{'code': 'aaa', 'name': 'a name'}, {'code': 'bbb', 'name': 'b name'}] In [2]: my_code = 'aaa' In [3]: print [d for d in my_lst if d['code'] == my_code] --> print([d for d in my_lst if d['code'] == my_code]) [{'code': 'aaa', 'name': 'a nam

Re: [Tutor] dictionaries help

2009-07-23 Thread Alan Gauld
"Alan Gauld" wrote Oops! Should be: def findDict(value, dictList): for dct in dictList: if dct.get('code', '') == my_code if dct.get('code', '') == value return dct HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___

Re: [Tutor] dictionaries help

2009-07-23 Thread Alan Gauld
wrote i would like to understand how dictionaries work. They work like a lookup table. You provide a key and lookup the corresponding value in the dictionary. So to implement a traditional language dictionary the keys would be words and the values would be a list of definitions. You read th

Re: [Tutor] dictionaries help

2009-07-23 Thread vince spicer
this should work def find_value(value, lst): for obj in lst: if value in obj.values(): return obj >> find_value("aaa", my_lst) Vince On Thu, Jul 23, 2009 at 9:55 AM, wrote: > hello, > please excuse me, but i would like to understand how dictionaris work. > > for examp

[Tutor] dictionaries help

2009-07-23 Thread davidwilson
hello, please excuse me, but i would like to understand how dictionaris work. for example: >>> my_lst = [{'code': 'aaa', 'name': 'a name'}, {'code': 'bbb', 'name': 'b >>> name'}] >>> my_code = 'aaa' from the above i would like to compare my_code and return the dictionary which has code == my_c