[(i+1)**2 for i in a if i%3!=2]
Goes through the list once, and reads like set notation!
(and does i+1 once, which is what I assume you were going for with the separate [i+1 for i in a]) [(i+1)**2 for i in a if i%3!=2]
Goes through the list once, and reads like set notation!
(and does i+1 once, which is what I assume you were going for with the separate [i+1 for i in a])In this example, yes, it's easy to solve the problem with only one iteration through the list. In a more complicated example (especially when the first map step is expensive and you really only want to do it once) this kind of solution may not work.