2006/12/20

List Comprehensions

Each list comprehension consists of an expression followed by a for clause, then zero or more for or if clauses.
The result will be a list resulting from evaluating the expression in the context of the for and if clauses which follow it. If the expression would evaluate to a tuple, it must be parenthesized.

[...for...]
>>> [str(round(355/113.0, i)) for i in range(1,6)]
['3.1', '3.14', '3.142', '3.1416', '3.14159']

沒有留言:

張貼留言