Create list from multiple lists
<p>I saved the results of a loop in a varibale. Now I have multiple (>500) separate lists. Which was okay for the beginning, but now I would like to work again with those lists. Do someone has an idea how I can create one list out of those multiple lists?</p>

<p>The code I have so far:</p>

<pre><code>for f in file:
 #do some stuff
  my_results =[]
  if score &gt;= 0:
   my_result.append(str(score))
  print my_result
</code></pre>

<p>So the results in my_result look like:</p>

<pre><code>['3']
['8']
['6']
 ...
</code></pre>

<p>But I want them to be like:</p>

<pre><code>[['3'], ['8'], ['6'],...]
</code></pre>

<p>I tried it this way:</p>

<pre><code>one_list = []
for item in my_result:
    one_list.append(item)
</code></pre>

<p>But unfortunately it didn't work!
So is there a way how I can combine all those lists to simply one list? </p>

<p>Thanks fo your help! :)</p>

<p>You are on the right track, but you seem confused about for loops. This should do what you want:</p>

<pre><code>my_result = []
for f in file:
    #do some stuff here
    if score &gt;= 0:
        my_result.append(str(score))
print my_result
</code></pre>

<p>The problem with your current code is that you keep setting <code>my_result</code> to an empty list <code>[]</code> for every item in file, thereby deleting all previous entries.</p>

<p>By the way, there is a typo throughout your code snippet as well as the other answer; <code>my_result</code> and <code>my_results</code> are two different lists so your code will not work because you want to assign to one list but actually assign to a completely different one.</p>

python python-2.7