Here's a fun way of counting words in a string in Python. This doesn't split the string then count, so it'll work for ridiculously large strings (e.g. files you can't load into memory) Plus, I had fun making it branchless (i.e., without explicit `if`s) by doing arithmetic with the flag `in_word` 😅
2 likes 2 replies
?