Possible Duplicate:
How do I randomly select an item from a list using Python?
I am trying to create a string that uses 3 different lists for 3 different words:
print (word1[random.randint(0, X )],
"the",
word2[random.randint(0, X)],
word3[random.randint(0, X)])
word1,word2 and word3 are different lists.
The X in randint is the amount of strings in the respective lists.
So, could anybody help me out and tell me how i write this code correctly?
word1[random.randint(0, [amount of strings in list "word1"])]
You’re making an unwarranted assumption that you need to pick such a random number. The random number is not the thing that you want; you want a random element of the string.
To make a random choice from a sequence, use
random.choice.