Hi,
 
A dictionary (associative array of keys and values) seems a good datatype to 
use.
vocab = {}
vocab[frenchword] = englishword
 
For instance:
>>> vocab = {"aimer": "love"}
>>> vocab
{'aimer': 'love'}
>>> vocab["parler"] = "speak"
>>> vocab
{'aimer': 'love', 'parler': 'speak'}
>>> for engword, frword in vocab.iteritems():
 print "%s - %s" % (engword, frword)
 aimer - love
parler - speak
 
But if one word has different meanings in the other language, you may need to 
use a list of words as the values.

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In the face of ambiguity, refuse the temptation to guess.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

--- On Thu, 2/4/10, Owain Clarke <simb...@cooptel.net> wrote:


From: Owain Clarke <simb...@cooptel.net>
Subject: [Tutor] language aid
To: tutor@python.org
Date: Thursday, February 4, 2010, 11:43 AM


Hello, all.

I am a newcomer to Python, and I know that I have much learning to do before I 
implement my idea, but I am working on the beginnings of a vocabulary building 
program. This is how I am catching new words at the moment.

def newVocab(x,y):
"""
Add new word pair, English word second.
Words to be separated by ':' """
x.append(y)

I can follow this with

french = []
newVocab(french,"souris:mouse")

The idea is that eventually the user would be prompted to enter a french (or 
whatever) word, and then to enter its English equivalent. The code would then 
be responsible for adding the ":" storing all the words in a list which would 
be written to a file, and recovering them as needed. Although i don't know how 
at this point, I assume I can search the part of the string before the colon or 
after, and thus set up vocabulary tests.

My question is, that if I proceed like this I will end up with a single list of 
potentially several hundred strings of the form "frword:engword". In terms of 
performance, is this a reasonable way to do it, or will the program 
increasingly slow down?

All suggestions appreciated


Owain Clarke

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



      
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to