In article <[EMAIL PROTECTED]>,
Erik Max Francis  <[EMAIL PROTECTED]> wrote:
>Alan Morgan wrote:
>
>> In article <[EMAIL PROTECTED]>,
>> Giovanni Bajo <[EMAIL PROTECTED]> wrote:
> >
>>>Because you assume that the only use-case of range() is within a for-loop.
>>>range() is a builtin function that can be used in any Python expression. For
>>>instance:
>>>
>>>RED, GREEN, BLUE, WHITE, BLACK = range(5)
>> 
>> Hmmm, this worked fine when I used xrange as well.  Am I missing something?
>
>Not in your use case.  Tuple unpacking will iterate, and so it doesn't 
>matter whether it's an actual list or an iterator:
>
> >>> a, b, c = xrange(3)
> >>> a
>0
> >>> b
>1
> >>> c
>2
>
>There are certainly contexts where a sequence and its iterator are not 
>interchangeable.  You missed an obvious one:
>
> >>> range(3) == xrange(3)
>False

I thought that one was sufficiently obvious as not to need mentioning.
There was never any argument that range() and xrange() returned different
things; the question (as I understood it) was if you could generally
use the things they return in the same way and not *care* about the
difference (the answer being "Yes, except when you can't").

Alan
-- 
Defendit numerus
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to