mercredi 29 mai 2019

How to choose random value from array, then choose randomly again excluding the value just chosen? (Python)

I am trying to create a combination of unique phrases to make a sentence and want to randomly select a phrase length from S (only needs to happen 1 time), and then randomly select first a J value, and then a random Q value, but I do not want the same value selected from J or S selected. How can I do this?

Here is what some of the sample outputs look like:

I3 and I1 I4 not I5 I5 or I4 and I3 not I3

Q=("but","why","okay")
J=("J1","J2","J3","J4","J5")
S=[(J), (J,Q,J), (J,Q,J,Q,J),(J,Q,J,Q,J,Q,J)]

' '.join([random.choice(i) for i in random.choice(S)])




Aucun commentaire:

Enregistrer un commentaire