Details about pythons set implementation

bukzor workitharder at gmail.com
Sat Jan 5 17:09:09 EST 2008


On Jan 4, 2:15 pm, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Fri, 04 Jan 2008 09:29:50 -0800, bukzor wrote:
> > Why cant you implement < for complex numbers? Maybe I'm being naive, but
> > isn't this the normal definition?
> >     a + bi < c + di iff sqrt(a**2 + b**2) < sqrt(c**2, d**2)
>
> No, it is not. Ordered comparisons are not defined for complex numbers.
> Which is bigger, 4+2j or 2+4j?
>
> > How do you implement a set without sorting?
>
> With a hash table.
>
> Or if you are willing to limit yourself to sets of small integers, you
> can implement it using bit flipping. E.g. 5 is an element of the set if
> bit 5 is on.
>
> > Are you expecting better than O(log n)?
>
> Sure.
>
> --
> Steven

Good Answers!



More information about the Python-list mailing list