title: Converting FiniteSet object to a python list
body: <p>I'm looking for a way to easily manipulate the results given by the <code>solveset</code> method in the SymPy package. In particular, I have a function <code>omega(x,n,p,gamma)</code> and I want to compute its roots while keeping <code>gamma</code> as a symbolic variable:</p>
  <pre><code>def omega(x,n,p,gamma):
      #do stuff
      
  gamma, x=var('gamma x')
  roots=solveset(omega_complete(x,30,1,gamma), x)
  </code></pre>
  <p><code>omega</code> returns a non-linear combination of <code>x</code> and <code>gamma</code>, so other methods in the same library such as <code>linsolve</code> or <code>solve</code> do not work. Currently I am stuck with an output of type <code>FiniteSet</code> after calling <code>solveset</code>: the result is printed in LaTeX and looks like <a href="https://i.stack.imgur.com/AYuVA.gif" rel="nofollow noreferrer">this</a>.</p>
  <p>The naive conversion <code>list(roots)</code> gives the error <code>TypeError: did not evaluate to a bool: None</code>. The alternative way that I found in <a href="https://stackoverflow.com/questions/38418205/get-a-value-from-solution-set-returned-as-finiteset-by-sympy">this answer</a> using <code>roots.args[0], roots.args[1]</code> is also not what I'm looking for. Can anyone help?</p>
  <hr />
  <p>The full code (note that are actually two functions, <code>omega_complete</code> and <code>omega_cycle</code>, that are similarly defined):</p>
  <pre><code>import numpy as np
  import cmath as cm
  from sympy import *
  
  def target(n,p):
      w=[]
      for j in range(n):
          if j==p:
              w.append(1)
          else: w.append(0)
      return np.array(w)
  
  ###---complete---####
  
  def change_basis_complete(N):
      
      matrix=np.zeros((N,N),dtype=complex)
      for n in range(0,N):
          for m in range(0,N):
              matrix[n,m]=(1/cm.sqrt(N))*cm.exp(2*np.pi*1j*(n+1)*(m+1)/N)
      return matrix  
  
  def new_target_complete(N,p):
      return np.dot(change_basis_complete(N),target(N,p))
  
  def omega_complete(x,N,p,gamma):
      
      w=new_target_complete(N,p)
      
      old_spectrum=np.zeros(N)
      for i in range(N-1):
          old_spectrum[i]=N
      old_spectrum[N-1]=0
      
      sigma=0
      for i in range(N):
          sigma+=(abs(w[i])**2)/(gamma*old_spectrum[i]-x)
      return 1-sigma
  
  ###---cycle---####
  
  def change_basis_cycle(N):
      
      matrix=np.zeros((N,N),dtype=complex)
      for n in range(0,N):
          for m in range(0,N):
              matrix[n,m]=(1/cm.sqrt(N))*cm.exp(-2*np.pi*1j*(n+1)*(m+1)/N)
      return matrix  
  
  def new_target_cycle(N,p):
      return np.dot(change_basis_cycle(N),target(N,p))
  
  def omega_cycle(x,N,p,gamma):
      
      w=new_target_cycle(N,p)
      
      old_spectrum=np.zeros(N)
      for n in range(N):
          old_spectrum[n]=2-2*cm.cos((2*cm.pi*n)/N)
     
      sigma=0
      for i in range(N):
          sigma+=(abs(w[i])**2)/(gamma*old_spectrum[i]-x)
      return 1-sigma
  </code></pre>