How to convert the string '1.000,0.001' to the complex number (1+0.001j)?
<p>The best I could come up with is</p>

<pre><code>s = '1.000,0.001'
z = [float(w) for w in s.split(',')]
x = complex(z[0],z[1])
</code></pre>

<p>Is there a shorter, cleaner, nicer way?</p>

<p>I guess you could do the slightly shorter</p>

<pre><code>real, imag = s.split(',')
x = complex(float(real), float(imag))
</code></pre>

<p>without involving the list comprehension.</p>

python complex-numbers