Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to remove duplicates for a list with in a function
    text
    copied!<p>this is what i have so far:</p> <pre><code>def unique_element(group): list=[] for element in group: piece=parse_formula(element) for x in piece: list.append(x[0]) return list #list(set(list)) </code></pre> <p>I have the other function below but this is the one I am trying to fix. Right now it returns a function with a list of letters but I do not want repeating letters. Example:</p> <pre><code>unique_element(['H2O2Y2','R3O2','Y2S3']) ['H', 'O', 'Y', 'R', 'O', 'Y', 'S'] </code></pre> <p>I thought using <code>list(set(list))</code> would work but when i run the function i get:</p> <pre><code>unique_element(['H2O2Y2','R3O2','Y2S3']) </code></pre> <p>Traceback (most recent call last):</p> <pre><code>File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "_sage_input_61.py", line 10, in &lt;module&gt; exec compile(u'print _support_.syseval(python, u"unique_element([\'H2O2Y2\',\'R3O2\',\'Y2S3\'])", __SAGE_TMP_DIR__) File "", line 1, in &lt;module&gt; File "/sagenb/sage_install/sage-5.4-sage.math.washington.edu-x86_64-Linux/devel/sagenb-git/sagenb/misc/support.py", line 479, in syseval return system.eval(cmd, sage_globals, locals = sage_globals) File "/sagenb/sage_install/sage-5.4-sage.math.washington.edu-x86_64-Linux/local/lib/python2.7/site-packages/sage/misc/python.py", line 56, in eval eval(z, globals) File "", line 1, in &lt;module&gt; File "", line 10, in unique_element TypeError: 'list' object is not callable </code></pre> <p>other functions:</p> <pre><code> from numpy import * from scipy import * from pylab import * import re def parse_formula(formula): '''Given a simple chemical formula, return a list of (element, multiplicity) tuples. Example: 'H2SO4' --&gt; [('H', 2.0), ('S', 1.0), ('O', 4.0)] ''' return [ (elem, float(mul) if mul else 1.) for (elem, mul) in re.findall(r'([A-Z][a-z]*)(\d*)', formula) ] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload