I have this:
self.lines = [...]
cnt = defaultdict(int)
for line in self.lines:
cnt[line] += 1
Now this works. But I wonder if it (incrementing count of particular lines in defaultdict) could be done using list comprehension?
This is a syntax error:
[cnt[line] += 1 for line in self.lines]
Incidentally, why can't one use expressions like this within list comprehension? It's straightforward and would greatly improved both terseness and performance of such code.