I am trying to write a function that will take a list of lists and print them out one by one with the word UNION between them. My code looks like this:
def printsql(lst):
print("INSERT INTO table")
for x in lst:
print("SELECT")
print(*x, sep=', ')
print("UNION")
return(str)
a = [[1, 3, 4], [2, 5, 7], [3, 4, 6]]
print(printsql(a))
My output currently looks like this:
INSERT INTO table
SELECT
1, 3, 4
UNION
SELECT
2, 5, 7
UNION
SELECT
3, 4, 6
UNION
This is almost exactly what I need but I can't figure out how to not print the last "UNION". Can someone advise?