6

I'm trying to improve my documentation. I want to say that this function accepts something that is a collections.Iterable, but the code will iterate over the iterable many times. A "list" is too specific, and an "iterable" doesn't work because some iterables can only be iterated once.

Is there a name for a thing? "Re-iterable"? Multiple-iterable?

4
  • 2
    Not answering your question, but I would suggest you might use itertools.tee in your code - so that it could accept any iterable at all. Commented Dec 12, 2011 at 14:31
  • @jsbueno: This would introduce a redundant copy when passing in a sequence, though. Commented Dec 12, 2011 at 15:01
  • 1
    @SvenMarnach: Actually, "tee" does just "the right thing" - it would only have "multiple copies" of sequence values that where used once, but not yet all times. The problem need to be one very resource-critical for this caching to be an issue at all. AND if it was, it would be a matter of an if for not using tee if a sequence was passed in. Commented Dec 12, 2011 at 17:56
  • @jsbueno: Why doesn't tee automatically do the right thing when a sequence is passed to it? Commented Jan 7, 2012 at 23:33

2 Answers 2

5

You probably want the term "sequence". A sequence in Python is something that has a length and supports item access by index.

Sign up to request clarification or add additional context in comments.

3 Comments

That might be too specific also though - for example a linked list doesn't support access by index, but is still reiterable.
@SideshowBob: I don't think this is too restrictive in practice. The only linked-list implementation that comes with Python is the chunked linked list deque, which is a sequence as well. Of course accessing by index is O(n) for a deque.
@SvenMarnach: A ValuesView is "reiterable", but doesn't support access by index in general.
2

I can't think of anything appropriate. Reiterable sounds like a nice term, why not define it clearly in your documentation then use it?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.