list comprehension
Simon Forman
rogue_pedro at yahoo.com
Fri Jun 30 21:34:44 EDT 2006
a wrote:
> hi simon thanks for your reply
You're most welcome
> what if i want to do this
> feed_list=[]
> feed_id=[]
> for ix in feeds_list_select:
> global feeds_list
> global feeds_id
> feeds_list.append(ix.url)
> feeds_id.append(ix.id)
>
> ie not one variable but more variables
> thanks
in a case like this I would usually reach for the zip() function, with
the "varargs" * calling pattern
N = [(ix.url, ix.id) for ix in feeds_list_select]
feed_list, feed_id = zip(*N)
or just
feed_list, feed_id = zip(*[(ix.url, ix.id) for ix in
feeds_list_select])
btw, please note that the global statements in your example are
unnecessary.. *totally* unnecessary. :-D
More information about the Python-list
mailing list