To the best of my understanding, this answers your question:

  iterable
         A container object capable of returning its members one at a
         time. Examples of iterables include all sequence types (such as
         list, str, and tuple) and some non-sequence types like dict and
         file and objects of any classes you define with an __iter__()
         or __getitem__() method. Iterables can be used in a for loop
         and in many other places where a sequence is needed (zip(),
         map(), ...). When an iterable object is passed as an argument
         to the builtin function iter(), it returns an iterator for the
         object. This iterator is good for one pass over the set of
         values. When using iterables, it is usually not necessary to
         call iter() or deal with iterator objects yourself. The for
         statement does that automatically for you, creating a temporary
         unnamed variable to hold the iterator for the duration of the
         loop. See also iterator, sequence, and generator.


bullockbefriending bard wrote:
Given:

class Z(object):
    various defs, etc.

class ZList(list):
    various defs, etc.

i would like to be able to replace

z_list = ZList()
for y in list_of_objects_of_class_Y:
    z_list.append(y)


with something like this:

z_list = [Z(y.var1, y.var2,..) for y in list_of_objects_of_class_Y]

Of course this just gives me a plain list and no access to the
methodsof z_list. I could, of course go and write a static method in
ZList which takes a plain list of Z objects and returns a ZList.

Anyway, my question is whether or not this can be done more elegantly
via list comprehension?


--
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
x-mozilla-html:FALSE
url:http://www.ncee.net
version:2.1
end:vcard

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to