title: How to create a when expression in spark with loops
body: <p>Hi I have a requirement to a create a column based on multiple <strong><em>when</em></strong> statements. </p>
  
  <pre><code>df.withColumn("new colume",when(col("col1").isin("list of item1"),"item1")
                             .when(col("col1").isin("list of item2"),"item2")
                             ....)
  </code></pre>
  
  <p>Is there anyway I can create a chain of <strong><em>when</em></strong> condition using a loop ? My plan is put input and output of <strong><em>when</em></strong> in a map like </p>
  
  <pre><code>Map("item1" -&gt; "list of item1","item2" -&gt; "list of item2")
  </code></pre>