Skip to content

Instantly share code, notes, and snippets.

@hiranp
Created December 28, 2023 22:40
Show Gist options
  • Save hiranp/9f3bfb8a3e995afd6e42cadb2d18a817 to your computer and use it in GitHub Desktop.
Save hiranp/9f3bfb8a3e995afd6e42cadb2d18a817 to your computer and use it in GitHub Desktop.
Simple replace word in place
import os
# https://github.com/first20hours/google-10000-english
CWD = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(CWD, "google-10000-english.txt")) as f:
words = [line.strip() for line in f]
# Convert single alphabet letters to their numeric values
for i in range(len(words)):
word = words[i]
if len(word) == 1 and word.isalpha(): # Check if the word is a single letter
numeric_word = str(ord(word) - 96)
words[i] = numeric_word # Replace the word in the original list
print(words)
# Write the words to a new file
with open(os.path.join(CWD, "converted_words.txt"), "w") as f:
for word in words:
f.write(f"{word}\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment