Its not so much a criterion that they *should* be used that way, its just that its what they do. A list comprehension creates a list! Thats why they are called *list* comprehensions. :-)
See, I'd always figured that the reason it was called a list comprehension was because the list comprehension operated on a list, and the operation was comprehension.
It can easily be checked by...
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]a = range(10) b = [x for x in a if x % 2 == 0] c = ['12','21','14','13'] d = [a[2] for x in c] a
[0, 2, 4, 6, 8]b
['12', '21', '14', '13']c
[2, 2, 2, 2]d
<type 'list'>type(a)
<type 'list'>type(b)
<type 'list'>type(c)
<type 'list'>type(d)
Everything I did with list comprehensions above shows that list comprehensions return a list.
Mostly it is evidenced by the type function...
Maybe, this post is silly?
Oh, well.
Jacob
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor