Can one get "for x in y" to work for non builtin classes?

castironpi at gmail.com castironpi at gmail.com
Sun Mar 2 11:09:24 EST 2008


On Mar 2, 8:15 am, Giles Brown <giles_br... at hotmail.com> wrote:
> On Mar 2, 2:08 pm, Preben Randhol <randhol
>
> +valid_for_reply_from_n... at pvv.org> wrote:
> > On Sun, 2 Mar 2008 15:06:17 +0100
>
> > Preben Randhol <randhol+valid_for_reply_from_n... at pvv.org> wrote:
> > >    class dbase(list):
>
> > Sorry the definition of the class is:
>
> >         class dbase(object):
>
> > it doesn't derive from the list class.
>
> > Preben
>
> http://docs.python.org/lib/typeiter.html

Be careful on your descision to return an ordered iterator or not--
that is, whether it iterates over the dictionary or the list (if I
understand you correctly).  If the order's unimportant then please
disregard.

You can also use:

>>> a= [2,3,4]
>>> b= iter( a )
>>> next( b )
2
>>> next( b )
3
>>> next( b )
4



More information about the Python-list mailing list