Python: take the content of a list and append it to another list
<p>I am trying to understand if makes sense to take the content of a list and append it to another list.</p>

<p>I have the first list created trough a loop function, that will get specific lines out of a file and will save them in a list.</p>

<p>Then a second list is used to save these lines, and start a new cycle over another file.</p>

<p>My idea was to get the list once that the for cycle is done, dump it into the second list, then start a new cycle, dump the content of the first list again into the second but appending it, so the second list will be the sum of all the smaller list files created in my loop.</p>

<p>The list has to be append only if certain conditions met, so I will just have to append when the criteria is met.</p>

<p>It looks like something similar to this:</p>

<pre><code># This is done for each log in my directory, i have a loop running
for logs in mydir:

    for line in mylog:
        #...if the conditions are met
        list1.append(line)

    for item in list1:
        if "string" in item: #if somewhere in the list1 i have a match for a string
            list2.append(list1) # append every line in list1 to list2
            del list1 [:] # delete the content of the list1
            break
        else:
            del list1 [:] # delete the list content and start all over
</code></pre>

<p>Does this makes sense or should I go for a different route?</p>

<p>I need something efficient that would not take up too many cycles, since the list of logs is long and each text file is pretty big; so I thought that the lists would fit the purpose.</p>

<p>Thanks for any suggestion!</p>

<p>Thanks to both of you Kirk and Sven for the solutions; I wish I could mark both with the checkmark!</p>
