On Wed, Jun 20, 2012 at 4:30 AM, Matthew Rocklin <[email protected]> wrote:
> (x for x in FiniteSet(1,2,3)).next() is the same as
> iter(FiniteSet(1,2,3)).next() or just FiniteSet(1,2,3).args[0]

Ah, that looks nice, I'll use it, thank you!

> The elements of a FiniteSet are actually ordered though (this solves a few
> problems and hasn't been a performance issue yet) so actually this should
> always return the minimum element, which may not what you want.

I see.

By "arbitrary" I meant that I didn't care which element exactly would
be extracted, since all elements in that set are all right for me.
Sorry, I should have explained it from the very beginning.

> The pop method of set does two things
> - it returns an element
> - it removes that element from the set
>
> This doesn't make sense for FiniteSet because it is immutable. The closest
> builtin class, frozenset, does not support a pop method but also forces you
> to use iter.

I see.  Thank you for the explanation!

On Wed, Jun 20, 2012 at 5:39 AM, Chris Smith <[email protected]> wrote:
> How about (for an *arbitrary* element):
>
>>>> random.choice(list(FiniteSet(1,2,3)))
> 1
>>>> random.choice(list(FiniteSet(1,2,3)))
> 2

Hm, that's a nice method, thank you!

However, I don't really care which element exactly gets extracted, I
just need one of them; therefore, I guess I'll stick to Matthew's
suggestion.

Sergiu

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to