Advertisement
namemkazaza

Z

Dec 8th, 2019
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. def have_adjacent_same(a):
  2.     for i in range(len(a) - 1):
  3.         if a[i] == a[i + 1]:
  4.             return True
  5.     return False
  6. from itertools import product
  7. alphabet, n = [i for i in input()], int(input())
  8. words, c = [i for i in product(alphabet, repeat=n) if have_adjacent_same(sorted(i))], 0
  9. for i in words:
  10.     for j in i:
  11.         print(j, end="")
  12.     c += 1
  13.     print()
  14. print(c)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement