> $ python -m timeit -s "s = set('abcdef')" "x = iter(s).next()"
> 100 loops, best of 3: 0.399 usec per loop
>
> $ python -m timeit -s "s = set('abcdef')" "x = s.pop(); s.add(x)"
> 100 loops, best of 3: 0.339 usec per loop
>
> So it looks like it's more efficient to use
On May 9, 11:41 am, Steven Bethard <[EMAIL PROTECTED]> wrote:
> $ python -m timeit -s "s = set('abcdef')" "x = s.pop(); s.add(x)"
It's interesting that that's faster. I'd be hesitant to use that in a
real program because it's so unattractive (as is the '.next()'
approach). To me a builtin
In <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
> Since any element of the set serves as a name (and you know the sets are
> all non- empty), it'd be very nice to have a .element() method, or some
> such. I guess "iter(s).next()" works okay, but it's not very readable,
> and I wonder if it's effi
[EMAIL PROTECTED] wrote:
> I've also previously run into the same need as the original poster. I
> no longer recall the details, but I think maybe I was implementing a
> union/find type algorithm. This basically involves partitioning a
> universe set into partitions, where any element of a partit
On May 4, 5:06 pm, John Machin <[EMAIL PROTECTED]> wrote:
> Errmm, union and intersection operations each apply to two (or more)
> sets, not to the elements of a set.
> You have n sets set0, set1,
>
> Let u be the number of unique somevalues (1 <= u <= n)
>
> If u > 1, then after setn = union
On 4 Mai, 10:23, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> > > It is not possible to index set objects. That is OK.
> > > But, what if I want to find some element from the Set.
>
> In the particular case, I have to read an attribute from any one of
> the elements, which one doesn't matter be
[EMAIL PROTECTED] wrote:
> In the particular case, I have to read an attribute from any one of
> the elements, which one doesn't matter because this attribute value is
> same across all elements in the set.
Someone else pointed out that there might be better data structures. If
performance was no
On May 4, 6:23 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> On May 4, 11:34 am, Peter Otten <[EMAIL PROTECTED]> wrote:
>
>
>
> > [EMAIL PROTECTED] wrote:
> > > It is not possible to index set objects. That is OK.
> > > But, what if I want to find some element from the Set.
>
> > > from sets
[EMAIL PROTECTED] wrote:
> On May 4, 11:34 am, Peter Otten <[EMAIL PROTECTED]> wrote:
>> A set is probably not the appropriate container then. What is your use
>> case?
> Peter, I need to do a lot of union and intersection operations on
> these elements. So, set is a must for me in this case.
>
On May 4, 11:34 am, Peter Otten <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > It is not possible to index set objects. That is OK.
> > But, what if I want to find some element from the Set.
>
> > from sets import Set
> > s = Set( range(12 )
>
> > if I do pop, that particular element get
> I do not want to remove the element, but get some element
> from the Set.
. . .
> Is there a way to do this. I am doing it like this:
>
> for x in s: break
>
> Now x is /some_element/ from s.
That is one way to do it. Another is to write:
x = iter(s).next()
One more approach:
x = s.po
On Thu, 03 May 2007 23:08:33 -0700, [EMAIL PROTECTED] wrote:
> It is not possible to index set objects. That is OK.
> But, what if I want to find some element from the Set.
>
> from sets import Set
> s = Set( range(12 )
>
> if I do pop, that particular element gets removed.
> I do not want to re
[EMAIL PROTECTED] wrote:
> It is not possible to index set objects. That is OK.
> But, what if I want to find some element from the Set.
>
> from sets import Set
> s = Set( range(12 )
>
> if I do pop, that particular element gets removed.
> I do not want to remove the element, but get some eleme
It is not possible to index set objects. That is OK.
But, what if I want to find some element from the Set.
from sets import Set
s = Set( range(12 )
if I do pop, that particular element gets removed.
I do not want to remove the element, but get some element
from the Set.
s.some_element() # Is n
14 matches
Mail list logo