If i understood you right, you can do it in one operation combineByKey:

from collections import Counter
x = sc.parallelize([(13, 'D'), (14, 'T'), (32, '6'), (45, 'T'), (47, '2'), (48, '0'), (49, '2'), (50, '0'), (51, 'T'), (53, '2'), (54, '0'), (13, 'A'), (14, 'T'), (32, '6'), (45, 'A'), (47, '2'), (48, '0'), (49, '2'), (50, '0'), (51, 'X')]) 
result = x.combineByKey(lambda value:  {value: 1}, 
...                     lambda x, value:  value.get(x,0) + 1,
...                     lambda x, y: dict(Counter(x) + Counter(y)))
result.collect()
[(32, {'6': 2}), (48, {'0': 2}), (49, {'2': 2}), (53, {'2': 1}), (13, {'A': 1, 'D': 1}), (45, {'A': 1, 'T': 1}), (50, {'0': 2}), (54, {'0': 1}), (14, {'T': 2}), (51, {'X': 1, 'T': 1}), (47, {'2': 2})]


PySpark reduceByKey? to add Key/Tuple
I'm trying to carve out sections from hundreds of XML files.  The structure of the XML docs is similar to:

&lt;document&gt;
&lt;nodes&gt;
&lt;node id=123&gt;pages of txt&lt;/node&gt;
&lt;node id-=124&gt;more example pages of txt and sub elements&lt;/node&gt;
&lt;/nodes&gt;&lt;/document&gt; 


I'm just trying to extract all &lt;node&gt; elements. I have been trying to use xmlstarlet: 

xmlstarlet sel -t -c “/document/nodes”


The problem is that it only returns &lt;/nodes&gt;. 

I just need to extract the following examples:

&lt;node id=123&gt;pages of txt&lt;/node&gt;
&lt;node id-=124&gt;more example pages of txt and sub elements&lt;/node&gt;


Can anyone recommend a better option, tool or approach? Many thanks.
