Coding Test/Python
[프로그래머스] 전화번호 목록(level2, python)
lim.dev
2024. 1. 10. 19:22
https://school.programmers.co.kr/learn/courses/30/lessons/42577
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
전체 코드
def solution(phone_book):
phone_book.sort()
for i in range(len(phone_book)-1):
if phone_book[i+1].startswith(phone_book[i]): return False
return True
str1.startswith(str2)는 str1이 str2로 시작하는지 검사해주는 메서드이다.
참고
https://codechacha.com/ko/python-find-something-starts-with-string/
Python - String startswith(), 어떤 문자열로 시작하는지 확인
startswith()를 이용하여 문자열이 특정 문자열로 시작하는지 확인할 수 있습니다. 예를 들어 다음과 같이 'Hello world, Python!'가 Hello로 시작하는지 확인할 수 있습니다. 만약 어떤 문자열이 포함하고
codechacha.com