250x250
vg-rlo
vg-rlo
vg-rlo
전체 방문자
오늘
어제
  • CATEGORY (114)
    • 일상과 기록 (12)
    • REVIEW (11)
    • DATA (20)
      • ML and DL (6)
      • NLP (2)
      • Growth hacking (2)
      • Note (10)
    • CODE (46)
      • Algorithm and Data Structur.. (2)
      • Coding Test (34)
      • DB (2)
      • Python (6)
      • Linux (2)
      • Github (0)
    • Portfolio (6)
      • Pratice and Tutorials (2)
      • Toy Projects (2)
      • Competitions (2)
      • Data Analysis (0)
    • ISSUE (17)
    • 🛠... (0)

블로그 메뉴

  • Github

인기 글

티스토리

hELLO · Designed By 정상우.
vg-rlo

vg-rlo

카테고리 없음

[Programmers] 해시 - 위장

2021. 6. 11. 02:30
프로그래머스 위장: https://programmers.co.kr/learn/courses/30/lessons/42578
 

코딩테스트 연습 - 위장

 

programmers.co.kr

 

실행 코드

def solution(clothes):
    answer = 0

    kinds = list(set(list(zip(*clothes))[1])) # 옷 종류 
    clothes_dict = dict.fromkeys(kinds, []) # dictionary 생성(key: 옷 종류, value: 해당 종류의 옷들)

    clothe_kinds_lst = list(set(list(zip(*clothes))[1]))
    clothe_kinds_all = list(zip(*clothes))[1]

    for k in kinds:
        clothes_dict[k] = clothe_kinds_all.count(k)
    
    cnt_mul = 1
    for cnt in clothes_dict.values():
        cnt_mul = cnt_mul * (cnt+1)
    return cnt_mul -1

if __name__ == '__main__':
    tests = [
        [["yellowhat", "headgear"], ["bluesunglasses", "eyewear"], ["green_turban", "headgear"]],
        [["crowmask", "face"], ["bluesunglasses", "face"], ["smoky_makeup", "face"]]
        ] # 2차원 배열로 된 옷

    result = [solution(test) for test in tests]
    print(result)

 

 

    vg-rlo
    vg-rlo
    🛠블로그 공사중.. Keep going! 🤔 (Profile - Dinotaeng®)

    티스토리툴바