coding

dictionary

임이레 2023. 4. 3. 15:47

- 딕셔너리 = {키1:값1, 키2:값2}

 

 

*how to make 

딕셔너리 = dict(key1= value1 , key2 = value2)

딕셔너리 = dict(zip([key1,key2],[value1, value2]))

딕셔너리  = dict([(key1, value1), (key2,value2)])

딕셔너리 = dict({key1 : value1 , key2 : value2})

 

# keys 

a = {'name': 'pey', 'phone': '010-9999-1234', 'birth': '1118'}

a.keys()

output : ['name', 'phone','birth'] 를 리턴한다.

 

#values 

a.values()

output : ['pey', '010-9999-1234' , '1118'] 를 리턴한다.

 

#items  ( key, value) 를 쌍으로 얻음

a.items()

output : [('name': 'pey'),('phone': '010-9999-1234'),('birth': '1118')]

 

#clear -> key:value 쌍을 모두 지움

a.clear()

output : {}

 

#get -> key로 value 얻기 

a.get('name')

output: 'pey'

 

a.get('iphone')

output: '010-9999-1234'

 

 

'coding' 카테고리의 다른 글

map function  (0) 2023.04.11
enumerate function  (0) 2023.04.08
한글폰트 error 해결  (0) 2022.12.18
얕은 복사와 깊은 복사  (0) 2022.12.16
요즘 드는 생각. (내가 가려는 길에 관하여)  (0) 2022.06.30