Re: checking if an object IS in a list

2008-07-21 Thread nicolas . pourcelot
On 20 juil, 07:17, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Sat, 19 Jul 2008 13:13:40 -0700, nicolas.pourcelot wrote: > > On 18 juil, 17:52, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > >> On Fri, 18 Jul 2008 07:39:38 -0700, nicolas.pourcelot wrote: > >> > So, I use somethi

Re: checking if an object IS in a list

2008-07-20 Thread nicolas . pourcelot
On 20 juil, 23:18, John Machin <[EMAIL PROTECTED]> wrote: > On Jul 21, 4:33 am, [EMAIL PROTECTED] wrote: > > > > (1) You are searching through lists to find float objects by identity, > > > not by value > > > > > You wrote """ > I used short lists (a list of 20 floats) and the element > checke

Re: checking if an object IS in a list

2008-07-20 Thread John Machin
On Jul 21, 4:33 am, [EMAIL PROTECTED] wrote: > > (1) You are searching through lists to find float objects by identity, > > not by value > > You wrote """ I used short lists (a list of 20 floats) and the element checked was not in the list. (That was the case I usually deals with in my code.)

Re: checking if an object IS in a list

2008-07-20 Thread nicolas . pourcelot
> (1) You are searching through lists to find float objects by identity, > not by value -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if an object IS in a list

2008-07-19 Thread Marc 'BlackJack' Rintsch
On Sat, 19 Jul 2008 13:13:40 -0700, nicolas.pourcelot wrote: > On 18 juil, 17:52, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: >> On Fri, 18 Jul 2008 07:39:38 -0700, nicolas.pourcelot wrote: >> > So, I use something like this in 'sheet.objects.__setattr__(self, >> > name, value)': >> > if t

Re: checking if an object IS in a list

2008-07-19 Thread John Machin
On Jul 20, 6:13 am, [EMAIL PROTECTED] wrote: > On 18 juil, 17:52, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > > On Fri, 18 Jul 2008 07:39:38 -0700, nicolas.pourcelot wrote: > > > So, I use something like this in 'sheet.objects.__setattr__(self, > > > name, value)': > > > if type(value)

Re: checking if an object IS in a list

2008-07-19 Thread nicolas . pourcelot
On 18 juil, 17:52, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > On Fri, 18 Jul 2008 07:39:38 -0700, nicolas.pourcelot wrote: > > So, I use something like this in 'sheet.objects.__setattr__(self, > > name, value)': > > if type(value) == Polygon: > >     for edge in value.edges: > >        

Re: checking if an object IS in a list

2008-07-18 Thread Terry Reedy
Peter Otten wrote: So, precisely, you mean that if hash(a) != hash(b), a and b are considered distinct, and else [ie. if hash(a) == hash(b)], a and b are the same if and only if a == b ? Correct for set, dict. For lists etc. the hash doesn't matter: Since CPython saves strings hashes as pa

Re: checking if an object IS in a list

2008-07-18 Thread Peter Otten
[EMAIL PROTECTED] wrote: >> What is your (concrete) use case, by the way? > > > > I try to make it simple (there is almost 25000 lines of code...) > I have a sheet with geometrical objects (points, lines, polygons, > etc.) > The sheet have an object manager. > > So, to simplify : > sheet

Re: checking if an object IS in a list

2008-07-18 Thread Marc 'BlackJack' Rintsch
On Fri, 18 Jul 2008 07:39:38 -0700, nicolas.pourcelot wrote: > So, I use something like this in 'sheet.objects.__setattr__(self, > name, value)': > if type(value) == Polygon: > for edge in value.edges: > if edge is_in sheet.objects.__dict__.itervalues(): > object.__setattr_

Re: checking if an object IS in a list

2008-07-18 Thread nicolas . pourcelot
> What is your (concrete) use case, by the way? I try to make it simple (there is almost 25000 lines of code...) I have a sheet with geometrical objects (points, lines, polygons, etc.) The sheet have an object manager. So, to simplify : >>> sheet.objects.A = Point(0, 0) >>> sheet.objects.B = P

Re: checking if an object IS in a list

2008-07-18 Thread bearophileHUGS
Peter Otten: > PS: Take these numbers with a grain of salt, they vary a lot between runs. Another possibility :-) from itertools import imap id(x) in imap(id, items) >If you want efficiency you should use a dictionary instead of the list anyway: I agree, but sometimes you have few items to look

Re: checking if an object IS in a list

2008-07-18 Thread Peter Otten
[EMAIL PROTECTED] wrote: > On 18 juil, 13:13, Peter Otten <[EMAIL PROTECTED]> wrote: >> [EMAIL PROTECTED] wrote: >> > In fact, 'any(myobject is element for element in mylist)' is 2 times >> > slower than using a for loop, and 'id(myobject) in (id(element) for >> > element in mylist)' is 2.4 times

Re: checking if an object IS in a list

2008-07-18 Thread nicolas . pourcelot
On 18 juil, 13:13, Peter Otten <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > In fact, 'any(myobject is element for element in mylist)' is 2 times > > slower than using a for loop, and 'id(myobject) in (id(element) for > > element in mylist)' is 2.4 times slower. > > This is not a meanin

Re: checking if an object IS in a list

2008-07-18 Thread nicolas . pourcelot
On 18 juil, 12:26, Peter Otten <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > I think something like > id(myobject) in (id(element) for element in mylist) > > would also work, also it's not so readable, and maybe not so fast > > (?)... > > > An "is in" operator would be nice... > >

Re: checking if an object IS in a list

2008-07-18 Thread Peter Otten
[EMAIL PROTECTED] wrote: > In fact, 'any(myobject is element for element in mylist)' is 2 times > slower than using a for loop, and 'id(myobject) in (id(element) for > element in mylist)' is 2.4 times slower. This is not a meaningful statement unless you at least qualify with the number of item

Re: checking if an object IS in a list

2008-07-18 Thread Peter Otten
[EMAIL PROTECTED] wrote: > I think something like id(myobject) in (id(element) for element in mylist) > would also work, also it's not so readable, and maybe not so fast > (?)... > > An "is in" operator would be nice... And rarely used. Probably even less than the (also missing) < in, | in

Re: checking if an object IS in a list

2008-07-18 Thread nicolas . pourcelot
In fact, 'any(myobject is element for element in mylist)' is 2 times slower than using a for loop, and 'id(myobject) in (id(element) for element in mylist)' is 2.4 times slower. -- http://mail.python.org/mailman/listinfo/python-list

Re: checking if an object IS in a list

2008-07-18 Thread nicolas . pourcelot
On 18 juil, 11:30, Peter Otten <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] wrote: > > Hi, > > > I want to test if an object IS in a list (identity and not equality > > test). > > I can if course write something like this : > > > test = False > > myobject = MyCustomClass(*args, **kw) > > for elem

Re: checking if an object IS in a list

2008-07-18 Thread Peter Otten
[EMAIL PROTECTED] wrote: > Hi, > > I want to test if an object IS in a list (identity and not equality > test). > I can if course write something like this : > > test = False > myobject = MyCustomClass(*args, **kw) > for element in mylist: > if element is myobject: > test = True >

checking if an object IS in a list

2008-07-18 Thread nicolas . pourcelot
Hi, I want to test if an object IS in a list (identity and not equality test). I can if course write something like this : test = False myobject = MyCustomClass(*args, **kw) for element in mylist: if element is myobject: test = True break and I can even write a isinlist(elt,