Skip to content

Instantly share code, notes, and snippets.

@RedStone576
Created October 8, 2025 17:21
Show Gist options
  • Select an option

  • Save RedStone576/082d4e70d4fef9026e1a1e6644d986f3 to your computer and use it in GitHub Desktop.

Select an option

Save RedStone576/082d4e70d4fef9026e1a1e6644d986f3 to your computer and use it in GitHub Desktop.
with open("./words.txt") as file:
whole = file.read()
i = 0
while i < len(whole):
if whole[i] == " " or whole[i] == "\n":
i += 1
continue
word = ""
j = i
while j < len(whole) and whole[j] != " " and whole[j] != "\n":
word += whole[j]
j += 1
count = 0
k = 0
while k < len(whole):
if whole[k] == " " or whole[k] == "\n":
k += 1
continue
word2 = ""
m = k
while m < len(whole) and whole[m] != " " and whole[m] != "\n":
word2 += whole[m]
m += 1
if word2 == word:
count += 1
k = m
already_printed = False
p = 0
while p < i:
if whole[p] == " " or whole[p] == "\n":
p += 1
continue
prev_word = ""
q = p
while q < len(whole) and whole[q] != " " and whole[q] != "\n":
prev_word += whole[q]
q += 1
if prev_word == word:
already_printed = True
break
p = q
if not already_printed:
print(word, "=", count)
i = j
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment