how to get a result without brackets in a list?
<p>I have a function which merges two sorted lists (a, b) into one sorted (c). If given lists have different lengths I need to insert the rest of the longest into the list c. But the way I did it - it gives the result with brackets inside the list c (for instance if a = [1,3,5] and b = [2,4,6] then the function returns [1,2,3,4,5,[6]]. How can I get rid of those brackets?</p>

<p>here`s my code</p>

<pre><code>def merge(a,b):
c = []
i = j = 0
while i &lt; len(a) and j &lt; len(b):
    if a[i] &lt; b[j]:
        c.append(a[i])
        i = i + 1
    elif b[j] &lt; a[i]:
        c.append(b[j])
        j = j + 1
    elif a[i] == b[j]:
        c.append(a[i])
        c.append(b[j])
        i = i + 1
        j = j + 1
if i &lt; len(a):
    c.append(a[i:])
if j &lt; len(b):
    c.append(b[j:])
return c
</code></pre>

<p>You should use <a href="https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types" rel="nofollow"><code>.extend()</code></a> in your last lines:</p>

<pre><code>if i &lt; len(a):
    c.extend(a[i:])
if j &lt; len(b):
    c.extend(b[j:])
</code></pre>

<p>because <code>a[i:]</code> and <code>b[j:]</code> are going to be lists</p>

<p>But I don't understand why you won't you use existing methods to your end result:</p>

<pre><code>a = [1, 3, 5]
b = [2, 4, 6]

c = a + b

c.sort()

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

<p>Won't that workÂ ?</p>

python list