
Aug. 27, 2008
11:17 p.m.
Tarek Ziadé wrote:
[transform(e) as transformed for e in seq if some_test(transformed)]
In my use case I would simply have to write;:
[l.strip() as stripped for l in text.split('\n') if stripped != '']
Which seems to me clear and concise.
-1 For me it is backward and confusing, whereas lines = [] for l in test: l = l.strip() if l: lines.append(l) is clear as could be. To me, the drive to replace all for loops with list comps is mis-directed. There is no end to the clauses people could propose to add: while, when, whatever, until, unless. mapped_to, transformed_by, and so on. The result would soon by something quite different from Python as we know it. tjr