[Tutor] python dictionary and loop

justin fargus fargusjustin at gmail.com
Wed Feb 29 00:04:22 CET 2012


Hello,

I am trying to do the following:

Make a program using two sentences of about 8 words (total between the two
sentences).  I would then like to create a dictionary {} and split the
words of each sentence using one sentence as a dictionary key and using the
other sentence for the dictionary value.  I would then like to use a loop
(while or for) that will write out a file that has the dictionary key and
dictionary value to it.  How can I go about doing this? I've noticed with
Python there is more than one way to do most things. I would like the
simplest so that I can practice over and over again on my own until I
understand it. Thanks in advance


I forgot to add in my first email that I am using Windows Vista 64x and
running Python 3.2.2.

The two sentences I would like to use in the program is the following:

"This is line one\nThis is line two!" so I write: text_message = "This is
line one\nThis is line two!"

The dictionary name and key/value pairs will be:

my_sentences {'This':'This','is':'is','line':'line','one':'two'}   # Does
this code split the words of each sentence so that the words in sentence 1
are keys, and the words in sentence 2 are values?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120228/9699186b/attachment-0001.html>


More information about the Tutor mailing list