Last active
September 23, 2018 01:02
-
-
Save LaPingvino/4b3bb144b367c773af99bb1a25542f22 to your computer and use it in GitHub Desktop.
Reads text from stdin, outputs CSV-formatted list of every unicode character (rune) in the file together with a number that says how much it appears
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// Because this code is so short and obvious, it should be considered public domain | |
import "os" | |
import "io/ioutil" | |
import "encoding/csv" | |
import "strconv" | |
func main() { | |
input, err := ioutil.ReadAll(os.Stdin) | |
if err != nil { | |
panic(err) | |
} | |
inputs := string(input) | |
output := map[rune]int{} | |
for _, c := range inputs { | |
output[c]++ | |
} | |
outputc := csv.NewWriter(os.Stdout) | |
for k, v := range output { | |
outputc.Write([]string{string(k), strconv.Itoa(v)}) | |
} | |
outputc.Flush() | |
if outputc.Error() != nil { | |
panic(outputc.Error()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment