๐ŸŒ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())

'๐ŸŒCoding > ๐ŸŒŸPython3' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[Python] lambda  (0) 2021.07.29
[Python] ์ˆœ์—ด, ์กฐํ•ฉ  (0) 2021.05.16
[๊ฐ€์ƒํ™˜๊ฒฝ] ํŒŒ์ด์ฌ ํ™˜๊ฒฝ์„ค์ •  (0) 2021.03.13
[Python] list  (0) 2021.02.09
[Python] ์ž…์ถœ๋ ฅ  (0) 2021.02.09