I am looking to use the lambda construct to create entries in list (which is basically a list of lists) that are of fixed length - 200. If the length is greater than 200, then I want to cut it 200 mark else pad it at the beginning. However, the following does not seem to work. Can anyone help on what is the right way to get this done using 1-line lambda.
P.S.: I have it done in multiple lines, but am wondering if I can make the above work.
features= [ r[:200] for r in reviews_ints if len(r) >= 200 else np.pad(r, (200 - len(r),0), 'constant', constant_values=(0)) ]
The error I get is:
File "<ipython-input-12-85a13ada1f6d>", line 1
features= [ r[:200] for r in reviews_ints if len(r) >= 200 else np.pad(r, (200 - len(r),0), 'constant', constant_values=(0)) ]
^
SyntaxError: invalid syntax
Thanks