Getting the first item for a tuple for eaching a row in a list in pyspark
<p>I'm a bit new to Spark and I am trying to do a simple mapping.<br>
My data is like the following:</p>

<pre><code>RDD((0, list(tuples)), ..., (19, list(tuples))
</code></pre>

<p>What I want to do is grabbing the first item in each tuple, so ultimately something like this: </p>

<pre><code>RDD((0, list(first item of each tuple),..., (19, list(first item of each tuple))
</code></pre>

<p>Can someone help me out with how to map this?<br>
I'll appreciate that! </p>

<p>You can use <code>mapValues</code> to convert the list of tuples to a list of tuple[0]:</p>

<pre><code>rdd.mapValues(lambda x: [t[0] for t in x])
</code></pre>

python apache-spark pyspark