title: PySpark: How to check if list of string values exists in dataframe and print values to a list
body: <p>I have a df <strong>NAMES</strong> in which if I output via <code>display(NAMES)</code>:</p>
  
  <pre><code>NAMES
  
  John
  
  Sarah
  
  Michael
  
  Sean
  </code></pre>
  
  <p>I also have a list  <strong>students</strong>, <code>print(students)</code>:</p>
  
  <p>{John, Alan, Andy}</p>
  
  <p><strong>Question</strong>:</p>
  
  <p>Based on this list (students), how can I loop through the df with "NAMES" Column and output to another list the names of students who are in the list and also in the DF.</p>
  
  <p>Expected output of list: "John" </p>
  
  <p><strong>I have tried</strong> </p>
  
  <pre><code>list2 = []
  for i in NAMES:
       for g in students:
          if i == g:
            list2.append(i)
  </code></pre>
  
  <p>but i end up with an error, how can i implement this via pyspark?</p>
  
  <p>Thanks.</p>