I am having trouble with list comprehension in Python
Basically I have code that looks like this
output = [] for i, num in enumerate(test): loss_ = do something test_ = do something else output.append(sum(loss_*test_)/float(sum(loss_))) How can I write this using list comprehension such as:
[sum(loss_*test_)/float(sum(loss_))) for i, num in enumerate(test)] however I don't know how to assign the values of loss_ and test_
c = a / float(b), do afrom __future__ import division; c = a / b, see this PEP. This is the default in Python 3.