list comprehension

a a at tempinbox.com
Sat Jul 1 16:43:18 EDT 2006


if i remove the global
i get an undefined error!
it was suggested as a solution in this group below

http://groups.google.com/group/comp.lang.python/browse_thread/thread/b7b2dcdc3e109f3e?hide_quotes=no#msg_81305eeee43f82c6
thanks
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