On Thu, 2008-01-03 at 15:20 +0000, Tom Badran wrote:
> Thanks for the hints Tim. The problem is that i'm not using the whole
> sequence, im just pulling one item out of the query set and was hoping
> for a way to get the position without having to use the whole set, in
> the same vain that count() is much more sensible a choice than len()
> as it gets optimised down to an SQL count by django. Thanks for
> pointing out enumerate though, im actually embarrassed i didn't know
> that, it looks very very useful. 

The problem is that you're asking for the equivalent of "given an object
x that came from a list L at some random point in the past, what is the
index of x in L?" Note that the answer is NOT necessarily L.index(x) for
Python lists, because that only finds the first occurrence of "x" (and
it's not L.index(x) for all iterable sequence, since the index concept
isn't necessarily determinable for a non-reversible iterator). What I'm
trying to say is that the general case is not solvable here. You need to
know how you got the original object to know where it came from. So it's
very much going to depend on how you pulled out the object 'x'.

Do you have some short code that demonstrates how you are extracting the
object in the first place? That might help with suggestions as to how
you can note the position later.

Regards,
Malcolm

-- 
Why be difficult when, with a little bit of effort, you could be
impossible. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to