Some pythonic advice needed

Moshe Zadka m at moshez.org
Sun Jun 1 10:15:51 EDT 2003


On Sun, 01 Jun 2003, Rudy Schockaert <rudy.schockaert at pandora.be> wrote:

> For some words there is more
> than one translation possible.

I assume the number of translation is usually small: it probably doesn't
even exceed 5, or 10 at most, right? In that case, the best is probably
to map original -> tuple of possible translation.

Then just check her answer for "in".

Here's an example, using antonyms instead of tranlsation:

import random
database = {
'light': ('dark', 'heavy'),
'easy': ('difficult',)
}

word = random.choice(database.keys())
print "give me an antonym for %s:" % word
answer = raw_input().strip()
if answer in database[word]:
    print "right"
else:
    print "wrong"

-- 
Moshe Zadka -- http://moshez.org/
Buffy: I don't like you hanging out with someone that... short.
Riley: Yeah, a lot of young people nowadays are experimenting with shortness.
Agile Programming Language -- http://www.python.org/





More information about the Python-list mailing list