Created
May 12, 2024 11:10
-
-
Save orjanv/da0036b73967a0eef16699fb64a74729 to your computer and use it in GitHub Desktop.
Finn norske palindromord basert på NSF-ordlista
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# | |
# Norske palindromord basert på NSF-ordlista | |
def palindrom_sjekk(ordet): | |
return ordet == ordet[::-1] | |
palindromer = [] | |
lengde = 7 | |
ordliste = 'nsf2022.txt' | |
def main(): | |
with open(ordliste, 'r') as fil: | |
for ordet in fil: | |
ordet = ordet.replace('\n', '') | |
if len(ordet) > lengde: | |
if palindrom_sjekk(ordet): | |
palindromer.append(ordet) | |
for i in sorted(palindromer, key=len): | |
print(i, len(i)) | |
print(f'\nTotalt {len(palindromer)} med {lengde} bokstaver eller mer') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment