Jan-11-2019, 04:01 PM
Quote:Albry wrote:
Im Sorry, this is a little advanced for me. I understand that what you have included is running through and matching what I needed but I'm still not sure on how to make it work. Would I be setting list1 as my 'guess' variable and list2 as 'question' ?
I misunderstood the original question.
I thought you were trying to show number of correct items in (guess history) list, as well as those in correct positions.
the example I showed (although not relevant now that I understand the question) was if you had a random list and a guess history list
as in a mastermind type of game, so example was:
Output:random_list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
guesses: [4, 8, 2, 0, 5, ...]
|____________ Correct Number, exact position
so all guesses are correct, but only one (5) is in the correct position, so
def show_correct_guess(random_list, guesses, exact=True): if exact: return [b for a, b in zip(random_list, guesses) if b == a] else: return [b for a, b in zip(random_list, guesses) if b != a]would return [4, 8, 2, 0] if exact is False
and [5] if exact is True