Answers for "python pairwise"

0

pairwise function python

# itertools — Functions creating iterators for efficient looping
# See : https://docs.python.org/3/library/itertools.html
import itertools
x = [A,1,B,2]
l = list(itertools.combinations(x, 2))
print(l)
[(A, 1), (A, B), (A, 2), (1, B), (1, 2), (B, 2)]
Posted by: Guest on July-26-2021
-1

itertools.zip_longest fill value

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___
Posted by: Guest on December-06-2020

Browse Popular Code Answers by Language