Re: Speaking of list-comprehension?
by Steven Bethard other posts by this author
Jun 30 2005 10:10PM messages near this date
Re: Speaking of list-comprehension?
|
Re: Speaking of list-comprehension?
Chinook wrote:
> >>> ta = [5, 15, 12, 10, 9]
> >>> for i in range(len(ta)):
> ... if ta[i] >= 10:
> ... ta[i] -= 10
> ... else:
> ... ta[i] += 10
> ...
> >>> ta
> [15, 5, 2, 0, 19]
One possibility:
py> [(tai + 10, tai - 10)[tai >= 10] for tai in ta]
[15, 5, 2, 0, 19]
But see:
http://www.python.org/peps/pep-0308.html
STeVe
--
http://mail.python.org/mailman/listinfo/python-list
Thread:
Chinook
Chinook
Chinook
Andrew Durdin
Terry Hancock
George Sakkis
Steven Bethard
George Sakkis
|