๐Coding/๐Python3
[Python] ๋์ ๋๋ฆฌ
๋ฟ์ผ._.
2021. 5. 2. 21:28
๋์ ๋๋ฆฌ ์ธ ๋๋ง๋ค ๊น๋จน..๐ต ์์ฃผ ์ฌ์ฉํ๋ ๊ฒ๋ง ์ ๋ฆฌํด๋ณด๊ฒ ์ต๋๋ฑ
๐๋์ ๋๋ฆฌ
- key: value ํ์์ผ๋ก ์ ์ฅํ ์ ์๋ ์๋ฃ๊ตฌ์กฐ
๐๋์ ๋๋ฆฌ ์ ์ธ
dic = {}
dic = dict()
dic = {"Key":"Value"}
๐๋์ ๋๋ฆฌ ์ถ๊ฐ
dic['์์ด๋']='๋น๋ฐ๋ฒํธ'
๐๋์ ๋๋ฆฌ ์ญ์
del dic['์์ด๋']
๐๋์ ๋๋ฆฌ Value ๊ฐ์ ธ์ค๊ธฐ
print(dic['์์ด๋'])
print(dic.get('์์ด๋'))
๐๋์ ๋๋ฆฌ Key ์๋์ง check
if '์์ด๋' in dic :
print("yes")
๐๋์ ๋๋ฆฌ value๋ฅผ ์ด์ฉํ์ฌ key ์ฐพ๊ธฐ
for key,value in arr.items():
if value=='value ๊ฐ':
print(key)
๐๋์ ๋๋ฆฌ -> list
list(dic.values())
๐๋์ ๋๋ฆฌ value์ ์ ๋ ฌ
dic = sorted(dic.items(), key=lambda x: x[1])
๐๋์ ๋๋ฆฌ key ์ ๋ ฌ
dic=sorted(dic.items())