I have the following code that works fine and I was wondering how to implement the same logic using list comprehension.
def get_features(document, feature_space):
features = {}
for w in feature_space:
features[w] = (w in document)
return features
Also am I going to get any improvements in performance by using a list comprehension?
The thing is that both feature_space
and document
are relatively big and many iterations will run.
Edit: Sorry for not making it clear at first, both feature_space
and document
are lists.
document
is a list of words (a word may exist more than once!)feature_space
is a list of labels (features)