[Tutor] question

hcohen2 hcohen2 at comcast.net
Mon Feb 9 17:59:04 EST 2004


R. Alan Monroe wrote:

>>I work with Python 2.3.3 and I try to make a programme that saves
>>words in a dictionary. And because I'm not a Python expert I don't know
>>how to do it or witch command I need. Could you please send me an example
>>of this case? 
>>    
>>
>
>The only command you need is the good old equal sign.
>
>mydict = {}
>
>mydict['myword'] = 'myword'
>
>
>  
>
Alan,

Nearly got it, but in a dictionary it is the dictionary key that is 
related to the value:

mydict[ myKey] = 'myword', try this

 >>> mydict = {}
 >>> mydict['key_to_my'] = "myword or anybody's word"
 >>> mydict
{'key_to_my': "myword or anybody's word"}

Notice I used the double quote, because I used the single quote in the 
string.

That should help.

Herschel

PS Read a bit about dictionaries: 
http://www.freenetpages.co.uk/hp/alan.gauld/
and check out http://www.python.org/topics/learn and a book I can 
suggest that will keep you busy: 'Learning Python - Second Edition' (I 
think I will be buying a copy soon though I own a coy of the first ed.).




More information about the Tutor mailing list