<div dir="ltr"><div>Hello,</div><div><br></div><div>I have a list of sql queries, some which are split across multiple list elements e.x.</div><div>['drop table sample_table;', 'create table sample_test', '(col1 int);', 'select col1 from', ' sample_test;']</div>
<div><br></div><div>A semi-colon in the string value  indicates the termination of a sql query. So the expected out come is a conversion to a list of valid sql queries:</div><div>['drop table sample_table;', 'create table sample_test (col1 int);', 'select col1 from sample_test;']</div>
<div><br></div><div>Here is the code that does that:</div><div><br></div><div>sample = ['drop table sample_table;', 'create table sample_test', '(col1 int);', 'select col1 from', ' sample_test;']</div>
<div>pure_sqls = []</div><div>query_holder= ''</div><div>for each_line in sample:</div><div>    query_holder += each_line</div><div>    if query_holder.endswith(';'):</div><div>        pure_sqls.append(query_holder)</div>
<div>        query_holder = ''</div><div><br></div><div><br></div><div>Is there a way to do this by eliminating explicit creation of new list(pure_sqls) and a temporary variable(query_holder)? Using list comprehension? Though I don't want to put the shorter version in production(if it is difficult to understand), I am looking if this can be done with list comprehension since I am trying to learn list comprehension by using it in such scenarios.</div>
</div>