list comprehension
a
a at tempinbox.com
Mon Jul 3 01:54:37 EDT 2006
hey guys
this is gr8
but in cheetah
i use
for test in $ix
$test.url
end for
to iterate thru loop
now how do i iterate feed_list and feed_id along with i,
thanks a lot
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])
Simon Forman wrote:
> 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