beginning index for generators

Andrew Dalke adalke at mindspring.com
Sun Oct 17 06:35:55 EDT 2004


Peter Otten
> No. That's what I would like xrange() to be.

Ahh, I had forgotten about that restriction.

BTW, this is kinda cute with your code

 >>> list(irange("A", "AAAAAAAAA", "A"))
['A', 'AA', 'AAA', 'AAAA', 'AAAAA', 'AAAAAA', 'AAAAAAA', 'AAAAAAAA']
 >>>

>>And that's itertools.islice?
> 
> 
> No, but it _calls_ itertool.islice() as you may have noted :-)
> Its raison d'être is that it allows to pass the start, stop, and step
> attributes of a slice object without looking into the special cases.

Acutally I didn't notice.  I was on my way out the door and didn't
look that closely.  My apologies.

Given the worry you had above about the sys.maxint limit, aren't
you also concerned about the same limits with itertools.islice?

> Yes, unfortunately. Discriminating between dictionaries and lists has been
> deliberately left out. Is there a recommended way to do it? Looking for a
> 'keys' attribute maybe?

No, because there are some data structure which act like both
a list and a dictionary.  Eg, one where the dictionary keys are
strings and the items are stored and accesible via integers
into the sort order.

				Andrew
				dalke at dalkescientific.com



More information about the Python-list mailing list