title: Replace elements in an array with its corresponding number in pyspark
body: <p>I have a dataframe shown below:</p>
  
  <pre><code>   +----------+--------------------------------+
     | Index    |           flagArray            |
     +----------+--------------------------------+
     |    1     | ['A','S','A','E','Z','S','S']  | 
     +----------+--------------------------------+
     |    2     | ['A','Z','Z','E','Z','S','S']  |
     +--------- +--------------------------------+
  </code></pre>
  
  <p>I want to represent array elements with its corresponding numeric values.</p>
  
  <pre><code>     A - 0
       F - 1
       S - 2
       E - 3
       Z - 4
  </code></pre>
  
  <p>So my output dataframe should look like </p>
  
  <pre><code>   +----------+--------------------------------+--------------------------------+
     | Index    |           flagArray            |           finalArray           |
     +----------+--------------------------------+--------------------------------+
     |    1     | ['A','S','A','E','Z','S','S']  | [0, 2, 0, 3, 4, 2, 2]          | 
     +----------+--------------------------------+--------------------------------+
     |    2     | ['A','Z','Z','E','Z','S','S']  | [0, 4, 4, 3, 4, 2, 2]          |
     +--------- +--------------------------------+--------------------------------+
  </code></pre>
  
  <p>I have written an udf in pyspark where I am achieving it by writing some if else statements. Is there any better way to handle the same.</p>