On Wed, Jan 11, 2012 at 9:49 AM, Noufal Ibrahim <nou...@nibrahim.net.in>wrote:
> Gora Mohanty <g...@mimirtech.com> writes: > > > [...] > > > It is not clear what you want from your description. To check if a > > list is empty, see if len( list ) is zero. > > [...] > > You don't want to do that. Your "list" might be a generator (unless you > check for type which is a bad idea anyway) and "len"ing that will > consume it which might be a potentially expensive operation. Noufal, Noticed something interesting as I was updating truth.py<https://gist.github.com/1327614#file_truth.py> to include generators and generator expressions; the `len` function doesn't handle generators at all. $ *python -c 'len(i for i in range(10))'* Traceback (most recent call last): File "<string>", line 1, in <module> TypeError: object of type 'generator' has no len() I'm pretty sure you just meant 'iterable' where you wrote 'generator', or didn't you? - d _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers