Skip to content

Instantly share code, notes, and snippets.

@cipri7329
Created December 12, 2016 16:00
Show Gist options
  • Save cipri7329/c7f6d1fa540f91fdc251802589898b81 to your computer and use it in GitHub Desktop.
Save cipri7329/c7f6d1fa540f91fdc251802589898b81 to your computer and use it in GitHub Desktop.
determine what is the most frequent CHARACTER in the file, and how many times was it used
//In the cell below, determine what is the most frequent CHARACTER in the README, and how many times was it used?
//spark and scala
var charCounts2 = readme.flatMap(line => line.toList).
filter( a => !a.equals("\n") && !a.equals(" ") && !a.equals("") ).
filter( _ != ' ').
map(character => (character, 1)).
reduceByKey((a,b) => a + b).
reduce((a, b) => if (a._2 > b._2) a else b)
//take(55).
//foreach( println)
println(charCounts2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment