On Fri, 03 Mar 2006 04:48:20 -0800, Iain King wrote:
> I think python only stores lists one way - i.e. each index maps to it's
> value, but no backwards trace is kept from value to index.
Python lists are arrays of pointers to objects. The objects themselves
have no clue what lists they belong to
Iain King enlightened us with:
> i = 0
> for object in list:
> objectIndex = i
> print objectIndex
> i += 1
Why not:
for index, object in enumerate(list):
print index
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity
William Meyer wrote:
> hi,
>
> I need to get the index of an object in a list. I know that no two objects
> in the list are the same, but objects might evaluate as equal. for example
>
> list = [obj1, obj2, obj3, obj4, obj5]
> for object in list:
> objectIndex = list.index(object)
> p
Iain King wrote:
> Iain King wrote:
> > William Meyer wrote:
> > > hi,
> > >
> > > I need to get the index of an object in a list. I know that no two
> > > objects
> > > in the list are the same, but objects might evaluate as equal. for example
> > >
> > > list = [obj1, obj2, obj3, obj4, obj5
Em Sex, 2006-03-03 às 12:48 +, William Meyer escreveu:
> Kent Johnson kentsjohnson.com> writes:
>
> > In either case enumerate() is your friend. To find an
> > item by identity:
> >
> > def index_by_id(lst, o):
> >for i, item in enumerate(lst):
> > if item is o:
> >return i
Iain King wrote:
> William Meyer wrote:
> > hi,
> >
> > I need to get the index of an object in a list. I know that no two
> > objects
> > in the list are the same, but objects might evaluate as equal. for example
> >
> > list = [obj1, obj2, obj3, obj4, obj5]
> > for object in list:
> > o
Kent Johnson kentsjohnson.com> writes:
> In either case enumerate() is your friend. To find an
> item by identity:
>
> def index_by_id(lst, o):
>for i, item in enumerate(lst):
> if item is o:
>return i
>raise ValueError, "%s not in list" % o
>
> If you just want the index
Iain King gmail.com> writes:
> what's wrong with:
>
> i = 0
> for object in list:
> objectIndex = i
> print objectIndex
> i += 1
>
> Iain
>
The issues with that is you might have a complex structure below the for object
in list: with lots of continues or breaks and you don't want
William Meyer wrote:
>I need to get the index of an object in a list. I know that no two objects
> in the list are the same, but objects might evaluate as equal. for example
>
> list = [obj1, obj2, obj3, obj4, obj5]
> for object in list:
>objectIndex = list.index(object)
>print objectI
Um, what about:
for oindex in xrange(len(list)):
object = list[oindex]
print oindex
You can't create a generic function for this.
Sebastjan
On 3/3/06, William Meyer <[EMAIL PROTECTED]> wrote:
> hi,
>
> I need to get the index of an object in a list. I know that no two objects
> in the
William Meyer wrote:
> hi,
>
> I need to get the index of an object in a list. I know that no two objects
> in the list are the same, but objects might evaluate as equal. for example
>
> list = [obj1, obj2, obj3, obj4, obj5]
> for object in list:
> objectIndex = list.index(object)
> pr
hi,
I need to get the index of an object in a list. I know that no two objects
in the list are the same, but objects might evaluate as equal. for example
list = [obj1, obj2, obj3, obj4, obj5]
for object in list:
objectIndex = list.index(object)
print objectIndex
prints 0, 1, 2, 3, 2
12 matches
Mail list logo