728x90
๋ฐ์ํ
- ๋งคํํ๊ธฐ ์ํจ
- key์ value๋ก ์ด๋ฃจ์ด์ง
{key1: Value1,key2:Value2,,,}
key์๋ hashableํ ๊ฒ๋ค์ ๋ฃ์ ์ ์์
value๋ ์ ํ์ด ์์
๋น ๋์ ๋๋ฆฌ ์ ์ธ
dict={}
์คํ ์์
dictionary={}
dictionary['first']=1
dictionary['tuple']=(1,2,3)
dictionary[(4,'tuple')]=1.5
print(dictionary)
###{'first': 1, 'tuple': (1, 2, 3), (4, 'tuple'): 1.5}
print(dictionary['tuple'])#(1, 2, 3)
print(dictionary[4,'tuple'])#1.5
dictionary['first']='one' #์ค๋ณต์ ๋ฎ์ด์์์ง
print(dictionary)
#{'first': 'one', 'tuple': (1, 2, 3), (4, 'tuple'): 1.5}
del dictionary['tuple']#์ญ์
print(dictionary)
#{'first': 'one', (4, 'tuple'): 1.5}
d={'ํ๊ตญ์ธ':2,'์๊ตญ์ธ':8,'ํ๋๋์ธ':5}
print(d.items()) #ํํ ๋ฆฌ์คํธํ์ผ๋ก ๋ณํ
print(d.keys())
print(d.values())
print(2 in d.values())
result
dict_items([('ํ๊ตญ์ธ', 2), ('์๊ตญ์ธ', 8), ('ํ๋๋์ธ', 5)])
dict_keys(['ํ๊ตญ์ธ', '์๊ตญ์ธ', 'ํ๋๋์ธ'])
dict_values([2, 8, 5])
True
๋ฐ์ํ
'Python > ์๋ฃ๊ตฌ์กฐ์ ์๊ณ ๋ฆฌ์ฆ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[python] ํ์ด์ฌ ๋ด์ฅํจ์ ๋ชฉ๋ก (0) | 2022.11.10 |
---|---|
[python ์๋ฃ๊ตฌ์กฐ] ์งํฉ set (0) | 2022.11.07 |
[python] ํ์ด์ฌ ํน์ง๊ณผ ์ฅ์ (0) | 2022.11.07 |
ํ heap, max heap, min heap ๊ฐ๋ (0) | 2022.11.01 |
์ด์งํ์ํธ๋ฆฌ (0) | 2022.11.01 |