> To my understanding, a slice isn't automatically a copy - it will be
> in most cases, but there are cases where the bytecode compiler will
> use the original list as an optimization. One example:
> 
>  >>> s = 'abc'
>  >>> t = s[:]
>  >>> s is t
>  True
>
> I'm willing to be corrected here, but my understanding was that for
> loop iteration was one of those optimization cases.

It looks like it's an immutable-optimization from my further 
testing (strings being immutable):

 >>> a = [1,2,3] # use a list (mutable)
 >>> b = a[:]
 >>> a is b
False

 >>> a = (1,2,3)  # use a tuple (immutable)
 >>> b = a[:]
 >>> a is b
True

> necessary for code clarity - I would contend that:
> 
> for x in intial_list[a:b]:
>    do stuff
> 
> is easier to read than:
> 
> sub_list = initial_list[a:b]
> for x in sub_list:
>    do stuff

in most cases, heartily agreed, so no contention here.

>> Yes, it would be nice if this worked because it's logically
>> true...except that it doesn't work (at least in Postgres and
>> MS-SQL Server):
> 
> Aw...crap. You are, of course, completely correct. I've been spending
> too much time in MySQL of late, and I forgot that this was an
> eccentricity of MySQL.

It's just a shame it's not readily available in other SQL 
flavors, as it bugs me every time I need to add umpteen GROUP BY 
entries just so I can get some values for the SELECT clause.

-tim



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to