[Python-Dev] PEP 289: Generator Expressions

Skip Montanaro skip at pobox.com
Thu Oct 23 11:48:15 EDT 2003


    Guido> No, I meant that "for x.a in mylist: ..." is valid but shouldn't
    Guido> be,

Valid?  I'll buy that, but it had never occurred to me.  Useful?  That's not
immediately obvious:

    >>> class Foo:
    ...   def __init__(self):
    ...     self.a = 42
    ... 
    >>> lst = [Foo() for i in range(4)]
    >>> lst
    [<__main__.Foo instance at 0x752760>, <__main__.Foo instance at
    0x7529e0>, <__main__.Foo instance at 0x752df0>, <__main__.Foo instance
    0x7529e0>at 0x752dc8>] 
    >>> [x for x.a in lst]
    [Type help() for interactive help, or help(object) for help about
    object., Type help() for interactive help, or help(object) for help
    about object., Type help() for interactive help, or help(object) for
    help about object., Type help() for interactive help, or help(object)
    for help about object.] 

Skip



More information about the Python-Dev mailing list