Skip to content

Instantly share code, notes, and snippets.

@adamori
Created January 18, 2023 14:28
Show Gist options
  • Save adamori/7a200334d91251b5fea556d59f2bd5ab to your computer and use it in GitHub Desktop.
Save adamori/7a200334d91251b5fea556d59f2bd5ab to your computer and use it in GitHub Desktop.
Token counter (for video: https://www.youtube.com/watch?v=2-pd03AwdSY)
print(f"Enter 'exit' to close")
while(True):
text = input("Enter your promt: ")
if text == 'exit':
exit()
words = text.split()
num_words = len(words)
num_dots = text.count(".")
num_commas = text.count(",")
print("Number of words:", num_words)
print("Number of dots:", num_dots)
print("Number of commas:", num_commas)
print("Total tokens:", num_words + num_dots + num_commas)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment