๐ ํ์ด์ฌ์ ๊ธฐ๋ณธ ๋ฐ์ดํฐ ๊ตฌ์กฐ
- ์คํ๊ณผ ํ
- ํํ๊ณผ ์งํฉ
- ์ฌ์
- Collection ๋ชจ๋
๋ฆฌ์คํธ๋ก ๊ตฌํ ๊ฐ๋ฅ
Push๋ append()
, Pop์ pop()
Put์ append()
, get์ pop(0)
์ ์ฌ์ฉ
set()
์ด๋ { }
๋ก ์ ์ธs1.union(s2)
/ s1 | s2
s1.intersection(s2)
/ s1 & s2
s1.differcence(s2)
/ s1 - s2
{Key1:Value1, Key2:Value2, ...}
์ ํํdict()
๋ { }
๋ก ์์ฑ
numbers = {"one" : 1, "two" : 2, "three" : 3}
numbers.items() ๐ ๋ฐ์ดํฐ ์ถ๋ ฅ (ํํ ํํ)
numbers.keys() ๐ ํค ๊ฐ๋ง ์ถ๋ ฅ
numbers.values() ๐ Value๋ง ์ถ๋ ฅ
numbers["four"] = 4 ๐ Dict ์ถ๊ฐ
from collections import deque
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
from collections import namedtuple
1. deque
list.append() ๋ฐ์ดํฐ ์ถ๊ฐ
list.appendleft() ๋ฐ์ดํฐ ์ผ์ชฝ์ ์ถ๊ฐ
list.rotate() ํ์นธ์ฉ ์ด๋
list.extend() ์ฌ๋ฌ ๋ฐ์ดํฐ ์ถ๊ฐ
2. OrderedDict
3. defaultdict
d = defaultdict(lambda : 0) ๐ 0์ผ๋ก ์ด๊ธฐ๊ฐ ์ค์
4. counter
5. namedtuple
{๊ตฌ์กฐ์ฒด} = namedtuple({๊ตฌ์กฐ์ฒด ์ด๋ฆ}, [{๊ตฌ์กฐ์ฒด ๋ณ์1}, {๊ตฌ์กฐ์ฒด ๋ณ์2}])
Point = namedtuple('Point',['x', 'y'])
p = Point(x = 11, y = 22)
print(p.x + p.y)
[๋ถ์คํธ์บ ํ AI Tech] Week 1 - Day 2