In Python how can I choose two or more random numbers from a given list,such that the numbers are chosen in the same sequence they are arranged in the list they are chosen from?It seems random.choice selects only one number from the list per iteration and as stated earlier random.sample does not give satisfactory answers.for example:
import random
a=['1','2','3','4','5','6','7','8']
b=['4','3','9','2','7','1','6','5']
c=random.sample(a,4)
d=random.sample(b,4)
print "c=",c
print "d=",d
The code gives me the following result:
c=['4','2','3','8']
d=['1','9','5','4']
But I want the answer as:
c=['4','5','6','7']
d=['9','2','7','1']
or
c=['5','6','7','8']
d=['7','1','6','5']