List Comprehension Python and PySpark

26 Views Asked by At

I have a pySpark application and I have to store a list of primary keys in a list using below code:

unique_keys = [row.KEY for row in df.select(primary_key).collect()]

This code is working; however, I do not want to hardcode the KEY as I stored it as a variable named primary_key. how can I specify the variable instead of KEY in the row.KEY part.

I would appreciate if anyone can help.

0

There are 0 best solutions below