https://www.notion.so/Data-Structure-2-Set-Dictionary-Hash-ffa428d2ef8149a7841a5ebbc80459ec
Set이란
array나 list처럼 순열자료구조(collection), but set에는 순서라는 개념이 없다.
Set 특징
>> my_set = {1, 2, 3, 4, 5, 1, 2} >> my_set {1, 2, 3, 4, 5} >> for i in my_set: ... print(i) ... 1 2 3 4 5 >> my_set.append(7) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'set' object has no attribute 'append' >> my_set[0] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'set' object does not support indexing >> my_set.add(7) >> my_set {1, 2, 3, 4, 5, 7} >> >> 5 in my_set # look up True
Set 구조
- hash는 one way 암호화 이다. 원웨이란 한번 암호화를 하면 복호화가 안된다.
- 실제 값의 길이와 상관없이 hash 값은 일정한 길이를 가집니다.
- 그럼으로 hash는 주로 임이의 길이를 갖는 임의의 데이터에 대해 고정된 길이의 데이터로 mapping할때 사용됩니다.
HashMap
hashmap이란?
kay-value형태의 값을 저장할 수 있는 자료구조.
ex) 이름은 "정우성" --> 실제 데이터 값과 데이터를 설명하는 key의 대응관계를 표현할때 유용하다.
>> my_dict = {1 : "one", "two" : 2, 3 : 3.0, 1: "one_one"} >> my_dict {1: 'one_one', 'two': 2, 3: 3.0} >> for key, value in my_dict.items(): ... print(f"{key} : {value}") ... 1 : one_one two : 2 3 : 3.0 >> my_dict[1] 'one_one' >> my_dict.get("two") 2 >> my_dict[5] Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 5 >> my_dict.get(5, 0) 0 >> my_dict[7] = "Seven" >> my_dict {1: 'one_one', 'two': 2, 3: 3.0, 7: 'Seven'}
hashmap 내부구조
언제사용하는가?