SymPy set objects are immutable, like every other SymPy object, so pop
could not work. However, iterating over the set does work. For finite
sets, the easiest way is to convert to a list. For countable infinite
sets, converting to a list won't work obviously, but you can use
iter(s) and call next() on it. Iteration is generally implemented so
that it hits every element (for instance, iterating over S.Integers
gives 0, 1, -1, 2, -2, ...). For uncountable sets like intervals, all
you can't iterate, but you can check containment using "in", or
intersect with other sets.

Aaron Meurer

On Wed, May 18, 2016 at 5:26 PM, Denis Akhiyarov
<[email protected]> wrote:
> Solveset is not indexable, so try converting to list. What surprised me is
> that it is not like regular python set:
>
> ptipython
> Python 3.5.1 |Anaconda custom (64-bit)| (default, Dec  7 2015, 11:16:01)
> Type "copyright", "credits" or "license" for more information.
>
>
> IPython 4.2.0 -- An enhanced Interactive Python.
> ?         -> Introduction and overview of IPython's features.
> %quickref -> Quick reference.
> help      -> Python's own help system.
> object?   -> Details about 'object', use 'object??' for extra details.
>
>
> In [1]: import sympy
>
>
> In [2]: sympy.__version__
> Out[2]: '1.0'
>
>
> In [3]: x=sympy.symbols('x',real=True)
>    ...: e,m=sympy.symbols('e,m',positive=True)
>    ...: sympy.solveset(sympy.sqrt(2*e*m-(x*m)**2),x)
> Out[3]: {-sqrt(2)*sqrt(e)/sqrt(m), sqrt(2)*sqrt(e)/sqrt(m)}
>
>
> In [4]: _
> Out[4]: {-sqrt(2)*sqrt(e)/sqrt(m), sqrt(2)*sqrt(e)/sqrt(m)}
>
>
> In [5]: sols=_
>
>
> In [6]: type(sols)
> Out[6]: sympy.sets.sets.FiniteSet
>
>
> In [7]: sols.pop()
> ---------------------------------------------------------------------------
> AttributeError                            Traceback (most recent call last)
> <ipython-input-7-188fe3e26bd2> in <module>()
> ----> 1 sols.pop()
>
>
> AttributeError: 'FiniteSet' object has no attribute 'pop'
>
>
> In [8]: list(sols)
> Out[8]: [sqrt(2)*sqrt(e)/sqrt(m), -sqrt(2)*sqrt(e)/sqrt(m)]
>
>
>
>
>
> On Tuesday, May 17, 2016 at 9:24:47 PM UTC-5, chaowen guo wrote:
>>
>> Hi:
>>
>> In sympy1.0, it is recommended to use solveset to solve equation, but how
>> to get the element of the solution?
>>
>> For example:
>>
>> import sympy
>> x=sympy.symbols('x',real=True)
>> e,m=sympy.symbols('e,m',positive=True)
>> sympy.solveset(sympy.sqrt(2*e*m-(x*m)**2),x)
>>
>> I want to get the first and second solution individually to do further
>> calculation, but I can not directly use [0] and [1], so how to get
>> individual element?
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/733f8e55-e2ad-438e-bd2a-792524801685%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BvjWU8ejwFrMEL5qF2voXmkwYMNiviqCUVxZBeyXQq_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to