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
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
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
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
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
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
"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/
___
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
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
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
10 matches
Mail list logo