https://school.programmers.co.kr/learn/courses/30/lessons/64064

from itertools import permutations
def solution(user_id, banned_id):
count = len(banned_id)
combinations = permutations(user_id, count)
answer = set()
# 각 조합에 대해 확인
for com in combinations:
found = True
# banned_id와 비교하기 위한 index 설정
for idx in range(count):
cid = com[idx]
bid = banned_id[idx]
# 길이가 다르면 바로 제외
if len(cid) != len(bid):
found = False
break
# 한 글자씩 비교
for i in range(len(cid)):
if bid[i] == '*':
continue
if bid[i] != cid[i]:
found = False
break
if not found:
break
if found:
answer.add(tuple(sorted(com)))
return len(answer)
user_id의 배열의 크기는 1이상 8이하라고 명시되어 있으므로 그냥 permutations 을 썼다. for idx in range(count): 를 할 생각을 못해서 시간이 오래걸렸다.