Re: [Tutor] Random module help

2007-10-07 Thread Norman Khine
Thank you, this is great. Alan Gauld wrote: > "Norman Khine" <[EMAIL PROTECTED]> wrote > > >> q_keys.sort() >> a = [q[x] for x in q_keys] > > a = [random.choice(q[x]) for x in q_keys] > >> So from this how do I choose a random element and produce a new >> dictionary like for example: > > Se

Re: [Tutor] Random module help

2007-10-06 Thread Alan Gauld
"Norman Khine" <[EMAIL PROTECTED]> wrote > q_keys.sort() > a = [q[x] for x in q_keys] a = [random.choice(q[x]) for x in q_keys] > > So from this how do I choose a random element and produce a new > dictionary like for example: See above. -- Alan Gauld Author of the Learn to Program web

Re: [Tutor] Random module help

2007-10-06 Thread Norman Khine
Hi Alan, Thanks for the suggestion, but I am not sure it is what I am after. From your dictionary, for example, I wanted to have a list as: "what is your name?" "where do you live?" then the next time I run the program I will get: "who are you? "what is your address? etc... rather then, what

Re: [Tutor] Random module help

2007-10-06 Thread Alan Gauld
"Norman Khine" <[EMAIL PROTECTED]> wrote > But what I was wondering if possible in achieving is that my > questions > set (q) contains questions that are similar, i.e. they are written > in > different ways, so I wanted to get the random set of unique > questions > rather then have variations

Re: [Tutor] Random module help

2007-10-06 Thread Norman Khine
Alan Gauld wrote: > "Norman Khine" <[EMAIL PROTECTED]> wrote > > a = [q[x] for x in q_keys] > a >> ['1q', '4q', '5q', '7q', '8q'] > a >> ['1q', '4q', '5q', '7q', '8q'] >> >> >> This only returns the same questions, what am I doing wrong? How do >> I >> return a different set? > > I

Re: [Tutor] Random module help

2007-10-06 Thread Alan Gauld
"Norman Khine" <[EMAIL PROTECTED]> wrote > >>> a = [q[x] for x in q_keys] > >>> a > ['1q', '4q', '5q', '7q', '8q'] > >>> a > ['1q', '4q', '5q', '7q', '8q'] > > > This only returns the same questions, what am I doing wrong? How do > I > return a different set? I don't understand your problem. Yo

[Tutor] Random module help

2007-10-06 Thread Norman Khine
Hello, I have an 'Exam' module which selects new random set of questions and displays it, well this is the idea n;). Here is what I have so far: >>> import random >>> n_question = 5 >>> q = {1:'1q', 2:'2q', 3:'3q', 4:'4q', 5:'5q', 6:'6q', 7:'7q', 8:'8q', 9:'9q', 0:'0q'} >>> if len(q) > n_que