Q:

How to Count Number of Items in List Within RDD

I have an RDD and each row has the following structure:
[(id,[listItem,listItem,ListItem])]

I have to go through the entire RDD and count the amount of list items.  I've tried something like this:
theCount = 0
theRDD.foreach(lambda x: theCount = theCount + x[1].count())
return theCount

but Python doesn't let me assign a value to theCount within the lambda function.  Does anyone know how to achieve this? 

A:

Something like this?  
sc.parallelize([('id', [1, 2, 3])]).map(lambda tup: (tup[0], len(tup[1]))).collect()

Output
[('id', 3)]

Spark doesn't send local variables across the job, throughout the cluster (even if running on a single, local node).  That's why the syntax you have isn't possible. 