목록전체 글 (147)
재 현
answer = True phone_book.sort() if p1,p2 in zip(phone_book, phone_book[1:]): if p2.startswith(p1): answer = False return answer
counter 모듈 : 데이터 요소 개수를 딕셔너리 형태로 반환하는 자료구조. 즉 리스트나 문자열과 시퀀스 자료형의 요소 중 값이 같은 것이 몇개 있는지 반환 ex) text = list("gallahad") text = ['g','a','l','l' ....] counter(text) = { 'a' : 3 , 'l' : 2 ...} counter['a'] = 3 프로그래머스 완주하지 못한 선수 문제를 풀 때 유용하게 쓰인 모듈 문자열에 특정문자가 몇개 들어있는지 확인할 때 쓰임
- 이름에 대해서 어떤 수를 기록하고 저장할 수 있는 구조 - 이름 대신 번호가 주어졌다면 ->배열 - 문자열로 원소를 찾아갈 수 있는 구조 -> 해시 1. d = {} for x in participants: d[x] = d.get(x,0)+1 for y in completion: d[x] -= 1 idx = list[k for k,v in d.items() if v>0] answer = idx 2. participants.sort() completion.sort() for i in range(len(participants)) if participants[i] in completion[i]: return participants[i] 3. answer = collections.counter(partici..