python automatically create parameters in a lambda function

Question:

constraint_condition = [lambda x: [x[0], x[1]]]
mid.gen_answer(constraint_ueq)

In codes above, mid is a class, and the method gen_answer is calling a function from another python package which requires n-dimension input written in this format:
lambda x:[x[0],x[1],...x[n]]

How do I create lambda function and fill these paramters automatically? For example I want a 4-dimension input, I shall be writing this by my hand like this:
lambda x:[x[0],x[1],x[2],x[3]], but what if there are more dimensions(like 12)? There is a way to let python write these (x[1],x[2]...) for me?

Asked By: Austie Chou

||

Answers:

Guy, I solved this by using lambda x:[sub_x for sub_x in x[:n]]. Thx for your help

Answered By: Austie Chou
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.