Convert length 1 nested lists into strings
<p>I have this list, in Python, with some nested lists inside with length 1:</p>

<p>[<strong>['7746']</strong>, '12', '1929', '8827', <strong>['7']</strong>, '8837', '128']</p>

<p>I want to get rid of the lists and just keep the string inside and get:</p>

<p>[<strong>'7746'</strong>, '12', '1929', '8827', <strong>'7'</strong>, '8837', '128']</p>

<p>How do I do this?</p>

<p>You can use a <a class='doc-link' href="http://stackoverflow.com/documentation/python/196/comprehensions/737/list-comprehensions#t=201609080600574325476">list comprehension</a> and a ternary conditional:</p>

<pre><code>empty = [(x[0] if isinstance(x, list) else x) for x in nested]
</code></pre>

<p>Alternatively, the obvious solution with a simple loop:</p>

<pre><code>empty = []
for x in nested:
    if isinstance(x, list):
        empty.append(x[0])
    else:
        empty.append(x)
</code></pre>

python list