title: How can I use "for" loop in spark with pyspark
body: <p>I met a problem while using spark with python3 in my project. In a Key-Value pair, like <code>('1','+1 2,3')</code>, the part <code>"2,3"</code> was the content I wanted to check. So I wrote the following code:<br>
  (Assume this key-Value pair was saved in a RDD called p_list)</p>
  
  <hr>
  
  <pre><code>def add_label(x):   
      label=x[1].split()[0]  
      value=x[1].split()[1].split(",")  
      for i in value:     
          return (i,label)  
  p_list=p_list.map(add_label)
  </code></pre>
  
  <hr>
  
  <p>After doing like that, I could only get the result: <code>('2','+1')</code> and it should be <code>('2','+1')</code> and <code>('3','+1')</code>. It seems like that the "for" loop in map operation just did once. How can I let it do multiple times? Or is there any other way I can use to implement such a function like "for" loop in map operation or reduce operation? </p>
  
  <p>I want to mention that what I really deal with is a large dataset. So I have to use AWS cluster and implement the loop with parallelization. The slave nodes in the cluster seem not to understand the loop. How can I let them know that with Spark RDD function? Or how can have such a loop operation in another pipeline way (which is one of the main design of Spark RDD)?</p>