Created
June 1, 2017 01:35
-
-
Save nattybear/3976f26e89e5b412400c4fa57a917de8 to your computer and use it in GitHub Desktop.
점프투파이썬 - 중복 숫자 문제
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 0~9까지 문자로 된 숫자를 원소로 갖는 set을 정의한다. | |
a = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} | |
def func(s): | |
# 입력한 원소의 총 개수가 10개가 아니라면 거짓을 리턴한다. | |
if len(s) != 10: return False | |
# 리스트 함수를 이용해서 한글자씩 쪼갠다. | |
s = list(s) | |
# set 함수를 이용해서 중복을 제거한다. | |
s = set(s) | |
# 미리 정의한 set a와 비교한다. | |
# 같다면 참을 리턴하고 | |
# 다르다면 거짓을 리턴한다. | |
if a == s: return True | |
else: return False | |
# 사용자 입력을 받는다. | |
s = input() | |
# 입력 받은 문자열을 func 함수에 넣는다. | |
r = func(s) | |
# 결과를 화면에 출력한다. | |
print(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
set 자료형을 이용
set 자료형은 아래와 같은 특징이 있지
때문에 이번 문제같이 어떤 내용이 있는지 없는지 검사를 하는 유형의 문제는 이 set 자료형을 적절히 사용하면 쉽게 공략 할 수 있다!