itertools Toolkit

Lab Python Advanced 30 points

Read two lines of words. Print the pairs with zip_longest (fill -), then all 2-letter combinations of the first line's first word (sorted letters, itertools.combinations), then the product of the first two words of each line joined by +.

Input

Two lines of words.

Output

Three lines.

Example

Input

cab dog
x y z

Output

cab/x dog/y -/z
ab ac bc
cab+x cab+y dog+x dog+y
Sample input available Sample output available
Editor
Python

Hints

zip_longest keeps going until the longer input ends.

product(a, b) is every pairing of a and b.

Solution explanation

itertools provides fast, memory-efficient building blocks for iteration.

Show solution
from itertools import combinations, product, zip_longest

a = input().split()
b = input().split()
print(*[f"{x}/{y}" for x, y in zip_longest(a, b, fillvalue="-")])
print(*["".join(c) for c in combinations(sorted(a[0]), 2)])
print(*[f"{x}+{y}" for x, y in product(a[:2], b[:2])])
Output
Answer
HOME LEARN COMMUNITY DASHBOARD