From de0fd379375e8e6444052fc249ffc5ef21ed2d44 Mon Sep 17 00:00:00 2001 From: osmala <ossi.laine@utu.fi> Date: Thu, 4 Jun 2020 11:39:38 +0300 Subject: [PATCH] Use prefilled list for basis to the results --- app/utils.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/utils.py b/app/utils.py index cbd4290..694062d 100644 --- a/app/utils.py +++ b/app/utils.py @@ -5,6 +5,9 @@ from itertools import zip_longest from flask import send_file +from app import app + + def timeit(method): def timed(*args, **kw): ts = time.time() @@ -82,20 +85,21 @@ def map_answers_to_questions(answers, questions): partial_answer = [None, None, None, None, 100, 99] ''' + # results = [] + results = list(map(lambda x: None, questions)) nth_answer = 0 - results = [] - - for question in questions: + for nth_question, question in enumerate(questions): - current_answer = answers[nth_answer] + try: + current_answer = answers[nth_answer] + except IndexError: + break if question_matches_answer(question, current_answer): - results.append(int(current_answer.answer)) + results[nth_question] = int(current_answer.answer) nth_answer += 1 - else: - results.append(None) return results -- GitLab