List of lists

W Isaac Carroll icarroll at pobox.com
Thu Jun 26 23:25:53 EDT 2003


Mike wrote:
> Ok, I'm doin an exercise and I need to expand on test.py. I'm pretty much
> done with the exercise except I need to print out the questions and answers
> that are in the function.
> 
> here is the snippet:
> 
> def get_questions():
>     return [["What color is the daytime sky on a clear day?","blue"],\
>                ["What is the answer to life, the universe and
> everything?","42"],\
>                ["What is a three letter word for mouse trap?","cat"]]
> 
> How do I get the lists from this?

     questions = get_questions()
     print questions[0][0]   # print first question (color of sky)
     print questions[0][1]   # print first answer ("blue")

TTFN






More information about the Python-list mailing list