All problems
Self-Consistency Vote
Problem
Majority-vote over several sampled answers and return the most common one. If there is a tie, return the smallest answer according to sorted order.
The signature is self_consistency_vote(answers).
Hint
Iterating keys in sorted order makes ties deterministic.
Test cases
case 1
in: [["a","b","a"]]
expected: "a"
case 2
in: [["b","a","a","b"]]
expected: "a"
case 3
in: [["z"]]
expected: "z"
case 4
in: [["a","b","c","a","c"]]
expected: "a"
Starter codePython
def self_consistency_vote(answers):
# Your code here
pass4 test cases · run your code against them in the editor