On Dec 10, 2009, at 1:55 AM, javier wrote:
> Well, the list comprehension doesn't make a lot of sense here.
I think they do. List comprehensions are quite fast and express the
intent well.
def diffE(a,b):
b = set(b)
return [x for x in a if x not in b]
Is both the fastest (on the dat
Hi Florent!
On Dec 10, 10:56 am, Florent Hivert
wrote:
> > AFAIK, a set is internally represented by a sorted binary tree that,
> > ideally, is balanced.
>
> I think that's not true. It is implemented as a hash table. Indeed, when you
> put something into a set, you need the element to be hashabl
but aren't all the hashable elements ordered in python ? You can
compare tuples, integers, Sets, etc...
I always wondered how these comparison worked ( and guesses hash
functions should be hiding somewhere )
Nathann
--
To post to this group, send an email to sage-devel@googlegroups.com
To unsub
Hi Simon,
> Not a big surprise, I would say. I mean, think what "v in b" does, if
> b is a list that does not contain v, and what it does if b is a set.
> AFAIK, a set is internally represented by a sorted binary tree that,
> ideally, is balanced.
>
> So, in order to find out that v is NOT
Nathann Cohen wrote:
> Thank you very much for your answers !!! I will try to fix these small
> issues along with real patches, as I go over the code in the Graph
> Section... Most of the time lists are used to represent sets, and I
> guess it can be improved in a few cases :-)
If you know the un
Thank you very much for your answers !!! I will try to fix these small
issues along with real patches, as I go over the code in the Graph
Section... Most of the time lists are used to represent sets, and I
guess it can be improved in a few cases :-)
Nathann
--
To post to this group, send an emai
Well, the list comprehension doesn't make a lot of sense here. Even if
you want to be as pythonic as possible, you don't want to run the
comprehension through all the elements on A, when you can do it just
in the elements of B:
def diffD(a,b):
c = copy(a)
for y in b:
c.remove(y)
Thankss !!! :-)
Nathann
2009/12/10 Carlo Hamalainen :
> On Thu, Dec 10, 2009 at 10:37 AM, Nathann Cohen
> wrote:
>> After a few tests, lists are slightly better for append/pop than set
>> is for add/remove. Obviously remove(i) for lists is linear, and hence
>> much longer than it is in
On Thu, Dec 10, 2009 at 10:37 AM, Nathann Cohen wrote:
> After a few tests, lists are slightly better for append/pop than set
> is for add/remove. Obviously remove(i) for lists is linear, and hence
> much longer than it is in sets...
Time complexity of various operations on sets, lists, dictionar
After a few tests, lists are slightly better for append/pop than set
is for add/remove. Obviously remove(i) for lists is linear, and hence
much longer than it is in sets...
I will take a look at the Graph section considering this :-)
Nathann
On Dec 10, 10:30 am, Nathann Cohen wrote:
> ( I forgo
( I forgot to add that in all these cases, lists represent Sets and
nothing else ( no repetition, no order, etc... ))
2009/12/10 Nathann Cohen :
> In understand, but then there are many places where lists are used in
> the Graph section where sets would greatly improve the performances !
>
> Natha
In understand, but then there are many places where lists are used in
the Graph section where sets would greatly improve the performances !
Nathann
2009/12/10 Simon King :
> Hi Nathann!
>
> On Dec 10, 9:02 am, Nathann Cohen wrote:
> [...]
>> time cA=diffA(a,b)
>> CPU times: user 29.36 s, sys: 0.
Hi Nathann!
On Dec 10, 9:02 am, Nathann Cohen wrote:
[...]
> time cA=diffA(a,b)
> CPU times: user 29.36 s, sys: 0.09 s, total: 29.45 s
> Wall time: 29.76 s
>
> time cB=diffB(a,b)
> CPU times: user 0.03 s, sys: 0.01 s, total: 0.04 s
> Wall time: 0.04 s
Not a big surprise, I would say. I mean, thi
Hello !!!
I just tried it, and I'm actually quite surprised
def diffA(a,b):
return [v for v in a if v not in b]
def diffB(a,b):
return list(Set(a).difference(Set(b)))
n=10
k=1
a = range(n)
b = list(Set([randint(0,n) for i in range(k)]))
time cA=diffA(a,b)
CPU times: user 29
On Dec 10, 8:58 am, Nathann Cohen wrote:
> Hello everybody !!!
>
> I recently had to write two very easy lines of python, and I wondered
> if there was ( there is ) a better way to write them. The problem is
> easy : I have a list A, a list B whose elements all belong to A, and I
> want to retur
15 matches
Mail list logo