Re: [Tutor] Dictionary Values Questions

2007-05-01 Thread Kent Johnson
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

[Tutor] Dictionary Values Questions

2007-05-01 Thread Tony Waddell
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

Re: [Tutor] dictionary values

2005-07-08 Thread Brian van den Broek
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

Re: [Tutor] dictionary values

2005-07-08 Thread Kent Johnson
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

Re: [Tutor] dictionary values

2005-07-08 Thread Kent Johnson
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

Re: [Tutor] dictionary values

2005-07-08 Thread Brian van den Broek
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

Re: [Tutor] dictionary values

2005-07-08 Thread Brian van den Broek
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

Re: [Tutor] dictionary values

2005-07-08 Thread Don Parris
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

[Tutor] dictionary values

2005-07-08 Thread luke p
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:

Re: [Tutor] dictionary values in strings

2005-05-20 Thread William O'Higgins
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':['

Re: [Tutor] dictionary values in strings

2005-05-19 Thread Max Noel
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

Re: [Tutor] dictionary values in strings

2005-05-19 Thread Bernard Lebel
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

[Tutor] dictionary values in strings

2005-05-19 Thread William O'Higgins
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