개발/파이썬
python. set 과 dict 차이
ttoance
2023. 10. 5. 06:00
배경
알고리즘을 풀다보면, map과 같이 고유한 값만 가지도록 체크해야 하는 경우고 있는데,
그 경우 나는 항상 dict를 썼었다.
그러다가, 다음 유투브를 통해 set의 존재를 알게되었다.
leetcode 풀이 > https://leetcode.com/problems/contains-duplicate/
https://www.youtube.com/watch?v=3OamzN90kPg
아래 블로그를 참고해서 정리했다.
https://daco2020.tistory.com/60
set과 dictionary의 차이점
1. dict와 set의 차이는 set에서 값(value)가 없다는 점이다.
2. dict와 set은 모두 중괄호로 정의된다.
a = {1: 'a', 2: 'b'} # dict
b = {1,2,'a','b'} # set
3. dict의 경우 키워드로 값을 찾기 위해, set의 경우 보통 list의 중복값 삭제용으로 사용한다.
보다가 list와 tuple의 차이점을 정리한 글도 있어서 가져왔다.
cf. list과 tuple의 차이점
1. list과 tuple 은 중복된 값을 넣을 수 있다.
2. list는 []를 사용하고, tuple은 ()를 사용한다.
반응형