title: Spark operations map,flatmap,filter,ReduceByKey, using python
body: <p>I want to some Spark filter and transformation for that I have the sample data,</p>
  
  <pre><code>657483, 888888, 9
  657483, 888889, 10
  657484, 888888, 20
  657484, 888889, 30 
  </code></pre>
  
  <p>For each <code>x[0]</code> I want to check condition to match <code>x[1] == '888888' &amp;&amp; x[1] == '888889'</code> and get relative x[2] so the output will look like,</p>
  
  <pre><code>657483,9,10
  657484,20,30
  </code></pre>
  
  <p>I want to do this using spark map,filter transformation. so i tried</p>
  
  <pre><code>result = (file1
      .map(lambda x: (x.split(",")[0],x))
      .groupByKey()
      .map(lambda x: (x[0], list(x[1])))  
      .sortByKey('true')
      .coalesce(1).map(lambda line: (line[0], if(line[1] == "888888"), and (line[1] == "888889"))).saveAsTextFile('hdfs://localhost:9000/filter'))
  </code></pre>
  
  <p>It gives me the results like,</p>
  
  <pre><code>657483,false,false
  
  657484,false,false
  </code></pre>
  
  <p>How can I extract the <code>x[0]</code> and <code>x[2]</code> which contain <code>x[1] == 888888 &amp;&amp; x[1] == '888889'</code>. How can we apply if condition to filter the result.</p>