Python Append String inside list just as an element without double quotes
<p>Editing my question so it is little clear:</p>

<p>Problem here is I want to put content of list1 inside List2. I was doing it wrong way as suggested in comments.</p>

<p>I get a list1 
value4 = [{'PARAMS': ['ProcessingDate=2016-08-29', 'ReRun=Y']}]</p>

<p>The elements of the PARAMS should be suffixed with '-param' string, so I created a new list with elements of value4[0]['PARAMS'] Then removed the square brackets of this list which ended up as string
FINALPARAMS 
<code>'-param', 'ProcessingDate=2016-08-29', '-param', 'ReRun=Y'</code></p>

<p>Then I was trying to insert these values inside another list as elements.</p>

<p><code>myNewlist = ['C:\This\Path', 'value2', 'value3', FINALPARAMS, 'value5']</code></p>

<p>This gives output with doublequotes around the FINALPARAMS values</p>

<p><code>['C:\\This\\Path', 'value2', 'value3', "'-param', 'ProcessingDate=2016-08-29', '-param', 'ReRun=Y'", value5]</code></p>

<p>I want to get rid of the double quotes inside this new list</p>

<p>-*********************************************************************-</p>

<p>Original Question:</p>

<p>This might be a easy solution for Python expert, but i am tired of finding solution. I have done most of the string manipulation I could do, like converting to string and trying out replace etc:</p>

<p>I have my list like below, I need to put the data of <code>value4</code> properly inside `mylist without double quotes.</p>

<p>using python 3.5</p>

<p>I get my <code>value4</code> like below</p>

<pre><code>   value4 = [{'PARAMS': ['ProcessingDate=2016-08-29', 'ReRun=Y']}]
</code></pre>

<p>I convert it to list like below, I need <code>-param</code> as suffix for my each element in <code>PARAMS</code></p>

<pre><code>paramlist   = value4[0]['PARAMS']
newparamlist = []
for x in paramlist:
    newparamlist.append('-param')
    newparamlist.append(x)
FINALPARAMS = (str(newparamlist)[1:-1]) #Taking out the squareBrackets
</code></pre>

<p><code>print FINALPARAMS</code> gives the desired result. i.e.</p>

<p><code>'-param', 'ProcessingDate=2016-08-29', '-param', 'ReRun=Y'</code></p>

<p>i use the <code>FINALPARAMS</code> in below list which prints value like this, i want to get rid of the double quotes and treat the string which i got from <code>FINALPARAMS</code> as normal list item inside the <code>myNewlist</code></p>

<p><code>myNewlist = ['C:\This\Path', 'value2', 'value3', FINALPARAMS, 'value5']</code></p>

<p><code>myNewlist</code> results as follows Observe the DoubleQuote I want to get rid of it so the values are treated as list items</p>

<p><code>['C:\\This\\Path', 'value2', 'value3', "'-param', 'ProcessingDate=2016-08-29', '-param', 'ReRun=Y'", value5]</code></p>

<p>I lost 4 hours finding the solution, which looked simple for me initially.
I tried converting this <code>newList</code> to string and replaced the doubleQuotes but my subprocess.checkoutput looks for proper list item</p>

<p>I tried converting the list to string and do <code>replace('"','')</code>  this turned out that it has put 4 backslashes to the windows path which is my first element in the list. and my command gave a error System cannot find the path specified</p>

<p>Here my code is present if someone wants to access and change it.
<a href="http://www.tutorialspoint.com/execute_python3_online.php?PID=0Bw_CjBb95KQMd1VkSW1tQnowS00" rel="nofollow">http://www.tutorialspoint.com/execute_python3_online.php?PID=0Bw_CjBb95KQMd1VkSW1tQnowS00</a></p>

<p>I believe you are confusing putting a <strong>list inside a list</strong> and <strong>concatenating two lists</strong>:</p>

<pre><code>[1, 2, paramlist, 5]         # [1, 2, [3, 4], 5]
</code></pre>

<p>is not the same as</p>

<pre><code>[1, 2] + paramlist + [5]     # [1, 2, 3, 4, 5]
</code></pre>

<p>Instead of using the correct operation you are trying to cast the list to a string to manually remove the square brackets. Needless to say this is the wrong way of doing it.</p>

<p>So i think you are looking for</p>

<pre><code>value4 = [{'PARAMS': ['ProcessingDate=2016-08-29', 'ReRun=Y']}]

paramlist = value4[0]['PARAMS']
paramlist = [elem for x in paramlist for elem in ('-param', x)]
myNewlist = ['Value1', 'value2', 'value3'] + paramlist + ['value5']

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

<p>which yields</p>

<pre><code>['Value1', 'value2', 'value3', '-param', 'ProcessingDate=2016-08-29', '-param', 'ReRun=Y', 'value5']
</code></pre>

python string list python-3.x