mirror of
https://github.com/KevinMidboe/knowit_julekalender-2018.git
synced 2025-10-29 17:50:19 +00:00
Renamed folders to have leading 0.
This commit is contained in:
48
luke_04/not_pal_but_an.py
Executable file
48
luke_04/not_pal_but_an.py
Executable file
@@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env python3.6
|
||||
# -*- coding: utf-8 -*-
|
||||
# @Author: KevinMidboe
|
||||
# @Date: 2017-12-04 16:40:56
|
||||
# @Last Modified by: KevinMidboe
|
||||
# @Last Modified time: 2017-12-04 20:20:28
|
||||
|
||||
def get_wordlist():
|
||||
with open('./ordliste.txt', 'r') as wordlist:
|
||||
read_data = wordlist.read().splitlines()
|
||||
wordlist.close()
|
||||
return read_data
|
||||
|
||||
def get_letter_instances(word):
|
||||
letter_instances = {}
|
||||
for char in list(word):
|
||||
try:
|
||||
letter_instances[char] = letter_instances[char] + 1
|
||||
except KeyError:
|
||||
letter_instances.update({char: 1})
|
||||
|
||||
return letter_instances
|
||||
|
||||
def can_be_palindrom(word):
|
||||
instance = get_letter_instances(word)
|
||||
values = list(instance.values())
|
||||
odd = 0
|
||||
for value in values:
|
||||
if (value & 1):
|
||||
odd += 1
|
||||
|
||||
return (odd <= 1)
|
||||
|
||||
def is_palindrom(string):
|
||||
return string == string[::-1]
|
||||
|
||||
def main():
|
||||
matches = []
|
||||
wordlist = get_wordlist()
|
||||
|
||||
for word in wordlist:
|
||||
if (not is_palindrom(word) and can_be_palindrom(word)):
|
||||
matches.append(word)
|
||||
|
||||
print(matches, len(matches))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user