How to select a name of a new list from existing string?
<p>I'm quite new to python and I'm not able to solve this. In a loop, I have a list with some numbers and a string with the desired name of the list. I want to create a new list identical to the existing list a named it according to the name from the string. </p>

<p><code>values = [1,2,3]
name='Ehu'</code></p>

<p>What I need is a new list named 'Ehu' containing the same items as the list values, but I don't know how to select a name of the new list from existing string. </p>

<p>Thanks</p>

<p>While you <em>can</em> do what you ask:</p>

<pre><code>&gt;&gt;&gt; globals()['Ehu'] = [1,2,3]
&gt;&gt;&gt; Ehu
[1, 2, 3]
</code></pre>

<p>or for local variables:</p>

<pre><code>&gt;&gt;&gt; def f():
...   f.__dict__['Ehu'] = [1,2,3]
...   print(Ehu)
...
&gt;&gt;&gt; f()
[1, 2, 3]
</code></pre>

<p>That is a bad practice.  A better solution as @Moses commented:</p>

<pre><code>&gt;&gt;&gt; list_names = {}
&gt;&gt;&gt; list_names['Ehu'] = [1,2,3]
&gt;&gt;&gt; print(list_names['Ehu'])
[1, 2, 3]
</code></pre>

python