ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved