Posted to tcl by dandyn at Fri Nov 22 17:32:32 GMT 2024view raw

  1. 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}
  2.  
  3. foreach word [regexp -all -inline {\w+} $data] {
  4. incr result([string tolower $word])
  5. }
  6. parray result
  7.  
  8.  
  9. puts \n
  10.  
  11. proc countWords {sentence} {
  12. set counts [dict create]
  13. foreach word [regexp -all -inline {[[:alnum:]']+} $sentence] {
  14. set w [string trim $word {'}]
  15. dict incr counts [string tolower $w]
  16. }
  17. return $counts
  18. }
  19. foreach {x y} [countWords $data] {
  20. if {[string is digit $x]} {continue}
  21. if {[string length $x] <= "3"} {continue}
  22. if {$y <= "4"} {continue}
  23. puts "$x $y"
  24. }

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week