📅  最后修改于: 2022-03-11 14:53:07.857000             🧑  作者: Mango
from itertools import zip_longest
chars = []
correct = 'hangman'
guess = 'winger'
for c, g in zip_longest(correct, guess, fillvalue='_'):
if c == g:
chars.append(c)
else:
chars.append('_')
print(chars)
# ['_', '_', 'n', 'g', '_', '_', '_']
word = ''.join(chars)
print(word)
# __ng___