tuple2 [자료구조] 좌석구매 파이썬 (hashable VS. unhashable) unique한 pair를 구하면 될거라 생각해서 2d 리스트를 그대로 set에 넣었지만 TypeError: unhashable type: 'list' unhashable 에러가 발생했다. 문제를 마저 풀기 전에 unhashable과 hashable의 차이점을 알아보자. 출처: realpython.com/lessons/immutable-vs-hashable/ hashable object라는 것은 can't modify 정도로 이해가 가능한데 좀 더 설명이 필요하기 때문에 다른 글을 찾아봤다. 요약: non-duplicate를 요구하는 python object들은 hashable하다. 출처: https://analytics4everything.tistory.com/m/138 2021. 4. 22. [LeetCode] Roman to Integer 파이썬 (dict, stack, deque) from collections import deque class Solution: def romanToInt(self, s: str) -> int: symbol = {"IV":4, "IX":9, "XL":40, "XC":90, "CD":400, "CM":900} roman = {"I":1,"V":5,"X":10,"L":50,"C":100,"D":500, "M":1000, "IV":4, "IX":9, "XL":40, "XC":90, "CD":400, "CM":900} stack = deque() stack.append((s[0],0)) for i in range(1, len(s)): pattern = stack[-1][0]+s[i] if pattern in symbol: stack.pop() stack.a.. 2021. 3. 26. 이전 1 다음