Dodany fragment w rubym i wejście ze słowami kluczowymi

This commit is contained in:
Michał Jurgo 2016-11-17 08:35:37 +01:00
parent 5b79910c3e
commit a0767a74c8
3 changed files with 18 additions and 47 deletions

View File

@ -1,47 +0,0 @@
monty = ["left", "chess", "back", "load"]
def getWordsSendDict(myList = []):
output = {}
output['Movement'] = checkMovement(myList)
output['Direction'] = checkDirection(myList)
output['Action'] = checkAction(myList)
print(output)
return output
def checkMovement(myList = [], *args):
file = open("movement.txt", 'r')
content = file.readlines()
content = [x.strip('\n') for x in content]
for i in content:
for j in myList:
if j == i:
file.close()
return i
file.close()
def checkDirection(myList = [], *args):
file = open("directions.txt", 'r')
content = file.readlines()
content = [x.strip('\n') for x in content]
for i in content:
for j in myList:
if j == i:
file.close()
return i
file.close()
def checkAction(myList = [], *args):
file = open("actions.txt", 'r')
content = file.readlines()
content = [x.strip('\n') for x in content]
for i in content:
for j in myList:
if j == i:
file.close()
return i
file.close()
getWordsSendDict(monty)

14
dictionary.rb Normal file
View File

@ -0,0 +1,14 @@
txt = open("input.txt")
filenames = ["actions.txt", "directions.txt", "movement.txt"]
dictionary = {}
txt.each_line do |line|
filenames.each do |name|
if File.read(name).include?line
dictionary[name.chomp('.txt')] = line.chomp("\n")
end
end
end
puts dictionary

4
keywords.txt Normal file
View File

@ -0,0 +1,4 @@
left
chess
back
load