Interface of the set classes
Steven Bethard
steven.bethard at gmail.com
Fri Oct 29 13:37:19 EDT 2004
More information about the Python-list mailing list
Fri Oct 29 13:37:19 EDT 2004
- Previous message (by thread): Interface of the set classes
- Next message (by thread): Line buffering pipes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Pierre Barbier de Reuille <pierre.barbier <at> cirad.fr> writes: > > I don't _need_ __getitem__ for itself. I need it because I don't know > how to iterate over a list and store the current position for future > use. I'm not sure I understand what you're trying to do here. Could you give an example? Iterators are resumable, so at least one sense of "storing the current position" is just retaining the iterator: >>> l = [11, 1, 2, 2, 3, 5, 11, 3, 7, 5] >>> items = iter(set(l)) >>> for i, item in enumerate(items): ... print item ... if i == 3: ... break ... 1 2 3 5 >>> for item in items: ... print item ... 7 11 If you could post an example of what you're doing right now with lst[x], maybe we could suggest some other ways of approaching it that take advantage of, say __iter__, instead of __getitem__? Steve
- Previous message (by thread): Interface of the set classes
- Next message (by thread): Line buffering pipes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list