On 18 Mar, 15:19, [EMAIL PROTECTED] wrote:
> Is there a function in Python analogous to the "where" function in
> IDL?
>
> x=[0,1,2,3,4,2,8,9]
> print where(x=2)
>
> output:
> [2,5]
You can try this:
print filter( lambda x: a[x]==2, range(len(a)))
However it's not the best solution...
--
http:
hi,
how would u improve this code?
class queue:
def __init__(self, size=8):
self.space = size
self.data = [None]*self.space
self.head = 0
self.tail = 0
self.len = 0
def __len__(self): return self.len
def push(self, x):
if self.len==self.
hi,
try this:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/190465
cheers.
--
http://mail.python.org/mailman/listinfo/python-list
http://groups.google.com/group/comp.lang.python/browse_thread/thread/32e545ebba11dd4d/49a9f0cc799cc1f1#49a9f0cc799cc1f1
--
http://mail.python.org/mailman/listinfo/python-list
thanks, nice job. but this benchmark is pretty deceptive:
try this:
(definition of unique2 and unique3 as above)
>>> import timeit
>>> a = range(1000)
>>> t = timeit.Timer('unique2(a)','from __main__ import unique2,a')
>>> t2 = timeit.Timer('stable_unique(a)','from __main__ import stable_unique,a
i suppose this one is faster (but in most cases efficiency doesn't
matter)
>>> def stable_unique(s):
e = {}
ret = []
for x in s:
if not e.has_key(x):
e[x] = 1
ret.append(x)
return ret
cheers,
przemek
there wasn't any information about ordering...
maybe i'll find something better which don't destroy original ordering
regards
przemek
--
http://mail.python.org/mailman/listinfo/python-list
Rubinho napisal(a):
> I've a list with duplicate members and I need to make each entry
> unique.
>
hi,
other possibility (my newest discovery:) )
>>> a = [1,2,2,4,2,1,3,4]
>>> unique = d.fromkeys(a).keys()
>>> unique
[1, 2, 3, 4]
regards
przemek
--
http://mail.python.org/mailman/listinfo/pyth