12 Sat

๋ฌธ์ž์—ด ๋‹ค๋ฃจ๊ธฐ ๊ธฐ๋ณธ

'''
https://programmers.co.kr/learn/courses/30/lessons/12918
๋ฌธ์ž์—ด ๋‹ค๋ฃจ๊ธฐ ๊ธฐ๋ณธ
[ํ’€์ด]
1. ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๊ฐ€ 4 ๋˜๋Š” 6์ด๋ฉด์„œ ์ˆซ์ž๋กœ๋งŒ ๊ตฌ์„ฑํ•˜๊ธฐ
2. str์„ int casting ํ•  ๋•Œ์˜ ์—๋Ÿฌ๋กœ ๊ตฌ๋ถ„.
'''
def solution(s):
    try: return str(int(s)) == s and (len(s) == 4 or len(s) == 6)
    except: return False
''' 
isalpha์™€ isdigit์„ ์‚ฌ์šฉํ•˜๋ฉด ์‰ฝ๊ฒŒ ๋ฌธ์ž์—ด์˜ ๋ฌธ์ž, ์ˆซ์ž ํŒ๋‹จ์„ ํ•  ์ˆ˜ ์žˆ๋‹ค.
or ์„ ์ด์šฉํ•œ ๋น„๊ต ๋ณด๋‹ค๋Š” in (4, 6)์œผ๋กœ ๋น„๊ตํ•˜๋ฉด ๊ฐ„๋‹จํ•˜๋‹ค.

def alpha_string46(s):
    return s.isdigit() and len(s) in (4, 6)
'''

Last updated

Was this helpful?