Scott David Daniels wrote:
Assuming you really are going for "is" comparison, how about:
max(id(x) for x in mylist) == min(id(x) for x in mylist)
It has the advantage that if [id(x) for x in mylist] = [2N, 1N, 3N],
you get the answer you desire.
Oops -- got me! -John
--
http://mail.python
On Wed, 15 Apr 2009 23:56:45 +0100, John Posner wrote:
Chris Rebert wrote:
Ah, okay. Then you want:
def all_same(lst):
return len(set(lst)) == 1
def all_different(lst):
return len(set(lst)) == len(lst)
Note that these require all the elements of the list to be hashable.
This solut
Chris Rebert wrote:
Ah, okay. Then you want:
def all_same(lst):
return len(set(lst)) == 1
def all_different(lst):
return len(set(lst)) == len(lst)
Note that these require all the elements of the list to be hashable.
This solution relies on the object ID -- no hashability required: