Add parentheses to list elements - Python
<p>I would like to retrieve a set of data in a file in the form of a list.</p>

<p>The following is the data i am reading from the file which I want to add to list:</p>

<blockquote>
  <h1>file input: (3,5),(5,2),(2,1),(4,2),(4,1),(3,1)</h1>
</blockquote>

<p>The following code shows what I have now:</p>

<pre><code>with open("partial.txt") as f:
List = f.read().splitlines()

graph1 = ','.join('({0})'.format(w) for w in List)

print (graph1)
</code></pre>

<p>The output I get is:</p>

<pre><code>&gt;&gt; (3,5),(5,2),(2,1),(4,2),(4,1),(3,1)
</code></pre>

<p>BUT I want the above result in [ ], like this:</p>

<pre><code>&gt;&gt; [(3,5),(5,2),(2,1),(4,2),(4,1),(3,1)]
</code></pre>

<p>Can someone show what I need to do to get the above result</p>

<pre><code>import ast

s = "(3,5),(5,2),(2,1),(4,2),(4,1),(3,1)"

&gt;&gt;&gt; list(ast.literal_eval(s))
[(3, 5), (5, 2), (2, 1), (4, 2), (4, 1), (3, 1)]
</code></pre>

<p>Here is an <a href="http://stackoverflow.com/questions/15197673/using-pythons-eval-vs-ast-literal-eval">SO link</a> to <code>eval</code> vs <code>ast.literal_eval</code></p>

python string list file