Python Forum

Full Version: CSV quiz
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I need to create a system where priority is given to choosing questions out of a list with the lowest number of times answered correctly first.

Any ideas what I could do?
Make a list of lists, with the sub-lists being the number of correct answers and the question.

questions = [[3, 'What is your name?'], [3, 'What is your quest?'], [1, 'What is your favorite color?'], [0, 'What is the capital of Assyria?']]
That will allow you to keep track of the number of correct answers, and you can sort the list to get the lowest number of correct answers first.
Thankyou so much.
Any idea on how to sort the list?
You might want to check out this tutorial on lists.
The list object has sort() method or you can use sorted() built-in function if you don't want to be done in place.

>>> questions = [[3, 'What is your name?'], [3, 'What is your quest?'], [1, 'Wha
... t is your favorite color?'], [0, 'What is the capital of Assyria?']]

>>> sorted_q = sorted(questions, key=lambda x: x[0])

>>> sorted_q
[[0, 'What is the capital of Assyria?'], [1, 'What is your favorite color?'], [3, 'What is your name?'], [3, 'What is your quest?']]