У меня есть функция, которая получает два файла .txt, один с задачами, а другой - с транзакторами. Возвращает список назначенных задач переводчикам.Как получить определенное значение из словаря?
В любом случае это еще не точка, Im пытается проверить, если данное значение по словарю переводчиков равно другому элементу в файле задачи, который является списком, это функция кстати:
def scheduleTasks(translators, tasks, date, hour, periodAfter):
"""Assigns translation tasks to translators.
Requires:
translators is a dict with a structure as in the output of
readingFromFiles.readTranslatorsFile concerning the update time;
tasks is a list with the structure as in the output of
readingFromFiles.readTasksFile concerning the period of
periodAfter minutes immediately after the update time of translators;
date is string in format DD:MM:YYYY with the update time;
hour is string in format HH:MN: with the update hour;
periodAfter is a int with the number of minutes of a period
of time elapsed.
Ensures:
a list of translation tasks assigned according to the conditions
indicated in the general specification (omitted here for
the sake of readability).
"""
Моя проблема заключается в том, как я могу получить значение из словаря, я знаю d.values (), но это возвращает все значения, как (это значение от одного ключа, только в качестве примера):
[' (portuguese; french)', ' (english)', ' 3*', ' 0.803', ' 3000', ' 25000', ' 3084', ' 08:11:2016\\n']
, но я просто хочу (португальский, французский) бит, если попытаться запустить что-то вроде
for translator in translators.values():
print translator[0]
возвращает «[», я не уверен, но я думаю, что это из-за того, как Linux записывает файлы, это функция им с помощью для чтения файла:
def readTranslatorsFile(file_name):
"""Reads a file with a list of translators into a collection.
Requires:
file_name is str with the name of a .txt file containing
a list of translators organized as in the examples provided in
the general specification (omitted here for the sake of readability).
Ensures:
dict where each item corresponds to a translator listed in
file with name file_name, a key is the string with the name of a translator,
and a value is the list with the other elements belonging to that
translator, in the order provided in the lines of the file.
"""
inFile = removeHeader(file_name)
translatorDict = {}
for line in inFile:
key = line.split(",")[INDEXTranslatorName]
value = line.split(",")[1::]
translatorDict[key] = str(value)
return translatorDict
И это входной файл:
Company:
ReBaBel
Day:
07:11:2016
Time:
23:55
Translators:
Ana Tavares, (english), (portuguese), 1*, 0.501, 2000, 20000, 2304, 08:11:2016
Mikolás Janota, (czech), (english; portuguese), 3*, 1.780, 2000, 200000, 4235, 08:11:2016
Paula Guerreiro, (french), (portuguese), 2*, 0.900, 3500, 45000, 21689, 11:11:2016
Peter Wittenburg, (dutch; english), (dutch; english), 2*, 1.023, 2500, 20000, 7544, 08:11:2016
Rita Carvalho, (english), (portuguese), 1*, 0.633, 5000, 400000, 18023, 09:11:2016
Steven Neale, (portuguese; french), (english), 3*, 0.803, 3000, 25000, 3084, 08:11:2016
@ Jean-FrançoisFabre Я знаю, что он все еще дает мне этот выход и просто хочет часть значения. – Exzlanttt
try 'list (translators.values ()) [0]' или 'next (translators.values () .__ iter __())' –
@ Jean-FrançoisFabre сначала возвращает [в одной строке и] на следующем; второй - это просто пустые строки. – Exzlanttt