Tony Waddell wrote:
> I am wondering how look for a key in a dictionary, given a value.
>
> I have a dictionary similar to this:
> a = { 'a1':1, 'a2':2, 'a3':3, 'a4'.:4}
>
> If I have the value of 2, how would I look at the dictionary to turn
> that into 'a2'.
You have to search the values. This
I am wondering how look for a key in a dictionary, given a value.
I have a dictionary similar to this:
a = { 'a1':1, 'a2':2, 'a3':3, 'a4'.:4}
If I have the value of 2, how would I look at the dictionary to turn
that into 'a2'.
___
Tutor maillist - Tut
Kent Johnson said unto the world upon 08/07/2005 21:09:
> Brian van den Broek wrote:
>
>>if you care about the possibility that there is no unique key with the
>>lowest value, I'd do:
>>
>> >>> def get_low_keys(a_dict):
>>... '''-> list of keys in a_dict with lowest value'''
>>... min_val = m
Brian van den Broek wrote:
> if you care about the possibility that there is no unique key with the
> lowest value, I'd do:
>
> >>> def get_low_keys(a_dict):
> ... '''-> list of keys in a_dict with lowest value'''
> ... min_val = min(a_dict.values())
> ... low_keys = []
> ... for k,v in
luke p wrote:
> just assume all the below code is correct.
> I am not having a problem with it, it is all for example only.
>
> I have a dictionary like this:
> alpha = {'a':0,'b':0, ... 'z':0}
> and the following code
> f = file("hamlet.txt","r")
> text = f.readlines()
> f.close()
> for line in t
luke p said unto the world upon 08/07/2005 19:40:
> just assume all the below code is correct.
> I am not having a problem with it, it is all for example only.
>
> I have a dictionary like this:
> alpha = {'a':0,'b':0, ... 'z':0}
> and the following code
> f = file("hamlet.txt","r")
> text = f.rea
Don Parris said unto the world upon 08/07/2005 20:09:
> On 7/8/05, luke p <[EMAIL PROTECTED]> wrote:
>>what I want to do is find out which value in my dictionary is lowest.
>>is there a dictionary function for this, like alpha.min() that will
>>return a key:value pair of the lowest? I cannot fi
On 7/8/05, luke p <[EMAIL PROTECTED]> wrote:
> just assume all the below code is correct.
> I am not having a problem with it, it is all for example only.
>
> I have a dictionary like this:
> alpha = {'a':0,'b':0, ... 'z':0}
> and the following code
> f = file("hamlet.txt","r")
> text = f.readline
just assume all the below code is correct.
I am not having a problem with it, it is all for example only.
I have a dictionary like this:
alpha = {'a':0,'b':0, ... 'z':0}
and the following code
f = file("hamlet.txt","r")
text = f.readlines()
f.close()
for line in text:
for char in line:
try:
On Thu, May 19, 2005 at 09:47:50PM +0100, Max Noel wrote:
>
>On May 19, 2005, at 20:49, William O'Higgins wrote:
>
>>I am trying to discover the syntax for call on a dictionary of
>>lists by
>>key and index.
>>
>>The data structure looks like this:
>>
>>dol = {'key1':['li1','li2','li3'],'key2':['
On May 19, 2005, at 20:49, William O'Higgins wrote:
> I am trying to discover the syntax for call on a dictionary of
> lists by
> key and index.
>
> The data structure looks like this:
>
> dol = {'key1':['li1','li2','li3'],'key2':['li1','li2','li3'],\
> 'key3':['li1'li2,'li3','']}
>
> The keys
Indeed, dictionaries don't have a .key attribute.
Instead, use:
# Get list of values for 'key1'
aList = dol[ 'key1' ]
This would return the list of values you have assigned to 'key1' in
the dictionary. Once you got that list, you can look in the list to
find out the index of 'lil1' and return i
I am trying to discover the syntax for call on a dictionary of lists by
key and index.
The data structure looks like this:
dol = {'key1':['li1','li2','li3'],'key2':['li1','li2','li3'],\
'key3':['li1'li2,'li3','']}
The keys are passed to a function as arguments, and I want the value of
the specif
13 matches
Mail list logo