Reputation: 6544
I use Python 3.4 and I have this code:
result = []
for i in r['resp']:
for id in self.all_dicts:
if i == id['id']:
result.append(id)
Its very long, so I want to short:
result = list(map(filter(lambda x: x == i,self.all_dicts),r['resp']))
But I have an error:
TypeError: 'filter' object is not callable
How to fix that? Thanks
Upvotes: 0
Views: 123
Reputation: 122061
I think you want:
result = [id for id in self.dicts if id['id'] in r['resp']]
Upvotes: 3