Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »

Review Suggested Edit

You can't approve or reject suggested edits because you haven't yet earned the Edit Posts ability.

Approved.
This suggested edit was approved and applied to the post over 3 years ago by Quintec‭.

24 / 255
Word Count Tool
  • In Google Docs, the word count tool looks like this:
  • ![Word count](https://codegolf.codidact.com/uploads/Howm5Y9o42uzdnEsnNrU1PHb)
  • Pages would not make sense, but your goal is to implement every other count.
  • # Definitions
  • **Words** are strings of text separated by any amount of whitespace (spaces, tabs, newlines).
  • **Characters** are all printable bytes*. For the sake of this challenge, you may assume all inputs will consist of printable bytes. Note that Google Docs does not count newlines in its character count, so you must do the same.
  • *I define printable bytes as the variable string.printable in Python, which is shown below.
  • ```
  • >>> string.printable
  • '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
  • ```
  • # Input
  • A string of text, or a list of strings instead of a multiline string if you wish.
  • # Output
  • The 3 counts (words, characters, characters without spaces) in any order, and in an array if you like.
  • # Examples
  • ```
  • Input -> [words, characters, characters without spaces]
  • "Hello world" -> [2, 11, 10]
  • "H3ll0 w0r1d" -> [2, 12, 10]
  • "Hello \t\nworld" -> [2, 12, 11]
  • "\n\n\n" -> [0, 0, 0]
  • " " > [0, 3, 0]
  • ```
  • This is code golf, so shortest code wins.
  • In Google Docs, the word count tool looks like this:
  • ![Word count](https://codegolf.codidact.com/uploads/Howm5Y9o42uzdnEsnNrU1PHb)
  • Pages would not make sense, but your goal is to implement every other count.
  • # Definitions
  • **Words** are strings of text separated by any amount of whitespace (spaces, tabs, newlines).
  • **Characters** are all printable bytes*. For the sake of this challenge, you may assume all inputs will consist of printable bytes. Note that Google Docs does not count newlines in its character count, so you must do the same.
  • *I define printable bytes as the variable string.printable in Python, which is shown below.
  • ```
  • >>> string.printable
  • '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
  • ```
  • # Input
  • A string of text, or a list of strings instead of a multiline string if you wish.
  • # Output
  • The 3 counts (words, characters, characters without spaces) in any order, and in an array if you like.
  • # Examples
  • ```
  • Input -> [words, characters, characters without spaces]
  • "Hello world" -> [2, 11, 10]
  • "H3ll0 w0r1d" -> [2, 12, 10]
  • "Hello \t\nworld" -> [2, 12, 11]
  • "\n\n\n" -> [0, 0, 0]
  • " " -> [0, 3, 0]
  • ```
  • This is code golf, so shortest code wins.

Suggested over 3 years ago by Razetime‭