Posted to tcl by dandyn at Fri Nov 22 17:32:32 GMT 2024view raw
- set data {Test Test test Test Test Test Test test test test test hello hello hello Hello test Hello Hello Hello hello hello hello test Hello}
- foreach word [regexp -all -inline {\w+} $data] {
- incr result([string tolower $word])
- }
- parray result
- puts \n
- proc countWords {sentence} {
- set counts [dict create]
- foreach word [regexp -all -inline {[[:alnum:]']+} $sentence] {
- set w [string trim $word {'}]
- dict incr counts [string tolower $w]
- }
- return $counts
- }
- foreach {x y} [countWords $data] {
- if {[string is digit $x]} {continue}
- if {[string length $x] <= "3"} {continue}
- if {$y <= "4"} {continue}
- puts "$x $y"
- }
Add a comment