문자열 before
와 after
가 매개변수로 주어질 때, before
의 순서를 바꾸어 after
를 만들 수 있으면 1을, 만들 수 없으면 0을 return 하도록 solution 함수를 완성해보세요.
before
after
before
after
before | after | result |
---|---|---|
"olleh" | "hello" | 1 |
"allpe" | "apple" | 0 |
입출력 예 #1
입출력 예 #2
def solution(before, after):
before_dict = {}
for i in range(len(before)):
if not before[i] in before_dict:
before_dict[before[i]] = 1
else:
before_dict[before[i]] += 1
after_dict = {}
for i in range(len(after)):
if not after[i] in after_dict:
after_dict[after[i]] = 1
else:
after_dict[after[i]] += 1
print(before[i])
print(before_dict, after_dict)
if after_dict == before_dict:
return 1
else:
return 0
https://school.programmers.co.kr/learn/courses/30/lessons/120886?language=python3