On Fri, 2011-09-23 at 17:04 +0200, Nils Philippsen wrote: > On Tue, 2011-09-20 at 11:29 -0400, James Antill wrote: > > There's no need to make this a multiline list generator, just using a > > for loop and append() is basically identical speed wise ... and stupid > > people like me can more easily read it :). > > You'll notice that we really want to annoy people when we start using > map() and filter(). :-P
My current feelings, which have changed over the last few years, is that given: 1. foo = [] for x in blah: if y: foo.append(x) 2. foo = [x for x in blah if y] 3. foo = filter(lambda x: y, blah) ...#1 is pretty much identical speed wise to the others, and everybody can understand it easily. The only downside is that for the most simple cases it has 2-4 times the vertically whitespace (but not much more typing). So if there is _any_ doubt, just use #1. #2 is fine when all of "x" "blah" and "y" are fairly simple. The limit is probably something like: return [pkg.pkgtup for pkg in self.returnPackages(patterns=patterns, ignore_case=False)] ...if it's just the test that is "non-simple" you can always put it in a function and use: foo = [x for x in blah if y(...)] ...if it's just the "blah", you can always use a generator. Or, again, just use a for loop. #3 is fine when the first arg. is _naturally_ a function, and the second is naturally a variable ... but just using a #2 is not a bad idea anyway. We do not worship lisp :). The general idea being that there is no reason to be "clever" for no reason, esp. as we have to do that too often anyway. _______________________________________________ Yum-devel mailing list Yum-devel@lists.baseurl.org http://lists.baseurl.org/mailman/listinfo/yum-devel