list comprehension question

Kirill Simonov kirill_simonov at mail.ru
Wed Mar 27 08:19:23 EST 2002


* Tim Peters <tim.one at comcast.net>:
> [Tripp Scott]
> > thanks for the tip. actually, the essence of what i wanted to
> > ask was: "can that SOMETHING be a list of more than one elements
> > which will be _flatly_ added to the result list."
> 
> No.  len([f(x) for x in y]) == len(y) whenever no exception occurs,
> regardless of the form of f() or type of y.


How about such f(x)?

def f(x):
    import sys
    sys._getframe(1).f_locals['_[1]'](-x)
    return x

def test(f, y):
    print 'len([f(x) for x in y]) = %s,' % len([f(x) for x in y]),
    print 'but len(y) = %s' % len(y)

test(f, range(10))


-- 
xi




More information about the Python-list mailing list