HELP! Simple question re: dictionaries

chibaA at TinterlogD.Tcom chibaA at TinterlogD.Tcom
Wed May 10 17:25:14 EDT 2000


Sorry.. forgot to ask another thing related to this:

1.  For the example below, how would I refer to JUST the key, value
referred to in the iteration of the for loop?

for key,value in argumentList.items():
	print ?

2.  Additionally, you can access a certain element of a list by using
a numerical subscript (like [1] - like an array).  If, let's say,
there's one key & corresponding value in a dictionary, then  how would
I reference that value - to let's say - print it out?

Finally... if you know of a website that I could visit to get the
specs of syntax, please let me know (so I can stop asking these simple
questions!).  

Thanks again for your help,

kc

On 10 May 2000 20:34:09 +0100, Michael Hudson <mwh21 at cam.ac.uk> wrote:

>chibaA at TinterlogD.Tcom writes:
>
>> Hi,
>> 
>> I just want to write a for statement to go through each element of a
>> dictonary.  I would have assumed it would look something like this
>> (argumentList being the dictonary):
>> 
>> for ___ in argumentList:
>> 	# whatever...
>> 
>> ... but I'm not sure of the exact syntax.  If anyone knows, could you
>> let me know?  Thanks!
>
>for key,value in argumentList.items():
>    # whatever ...
>
>is pretty idiomatic...
>
>Cheers,
>M.
>
>-- 
>34. The string  is a stark data  structure and  everywhere it is 
>    passed there is much duplication of process. It is a perfect 
>    vehicle for hiding information.
>     -- Alan Perlis, http://www.cs.yale.edu/~perlis-alan/quotes.html




More information about the Python-list mailing list