'PYSPARK & SQL nested list comprehension: how to select specific iterations in the for loop

I have two lists that I want to use string manipulation on.

sourceTable=["customer_{KERNEL}","material_{KERNEL}"]
kernel=["a","b","c"]

My output needs to look like this:

SELECT * FROM customer_a x LEFT JOIN material_a y ON x.id=y.id
SELECT * FROM customer_b x LEFT JOIN material_b y ON x.id=y.id
SELECT * FROM customer_c x LEFT JOIN material_c y ON x.id=y.id

I have been trying to get it to work by using nested list comprehensions but I have been struggling as the order in which the items in the list appear does not work.

Can anyone help and point me in the right direction?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source