Reputation: 105
I am trying to generate a list of values that append another list as parameter in the order shown below in the 'parameters' list.
How may I go about appending 'parameters' to 'vector' with random values upon each iteration of the for loop?
e.g. Desired output appending 'parameters' twice to 'vector' [ 2, 14000, 120, 1, 12000, 80]
def generate_vector(self):
parameters = [lambda:random.randint(0, 3), lambda:random.randint(0, 400000), lambda:random.randint(0, 128)]
vector = []
path, dirs, files = os.walk("templ_list/").next()
file_count = len(files)
for file in files:
vector.append(parameters)
return vector,
Upvotes: 1
Views: 119
Reputation: 927
You can create a generator for your Parameters and flatten the list with sum.
params_gen = ((random.randint(0, 3), random.randint(0, 400000), random.randint(0, 128)) for _ in range(len(files)))
vector = sum(params_gen, ())
Upvotes: 1