---메인------
result = get_property_unit(tickers)
print(result)
-----함수--------
def get_property_unit(tickers):
infos = get_infos()[0]
result = {ticker:0 for ticker in tickers}
for info in infos:
if info['name1'] == '김':
continue
ticker = "김" + info['name2']
tmp = float(info['property'])
result[ticker] = tmp
return result
get_infos는
{'name1': '김', 'name2': '철수', 'property': '999.999', 'hobby': '수영', 'height': '111', 'age': '16'}
이런 식으로 된 딕셔너리고
tickers는 사람 이름들 있는 딕셔너리인데
if info['name1'] == '김':
TypeError: string indices must be integers
위 같이 오류가 뜨네
검색해보니 딕셔너리는 타입이 정수형만 와야 된다는데 그럼 코드 전체를 바꿔야 되나?
프로그래밍 너무 어렵다 ㅠㅠ
infos 변수 출력하면 글에적어둔 딕셔너리가 나온다는거야? 아님 getinfos 메서드의 반환한게 그거란거? - dc App
get info[0]면 'name' : '김'이라는 키 밸류 쌍이 되지 더이상 딕셔너리가 아닐거임 - dc App
걍 간단하게 확인해보고 싶으면 print(info, type(info)) - dc App
dictionary 에 저렇게 for문 돌리면 key값들이 나옵니당 아마 info 자체가 'name1' , 'name2' 같은게 되는거
for in을 잘못썻네
for in 안에 print(info)해서 뭐 나오는지 확인해보셈