의 목록에서 딕셔너리에서 값을 얻을 수 있습니다 :어떻게 dicts dicts이 목록에서
lst = [{'fruit': 'apple', 'qty':'4', 'color': 'green'},
{'fruit': 'orange', 'qty':'6', 'color': 'orange'},
{'fruit': 'melon', 'qty':'2', 'color': 'yellow'}]
내가 'color'
키의 값이 'yellow'
인 'fruit'
키의 값을 얻을 싶어요.
any(fruits['color'] == 'yellow' for fruits in lst)
내 색상이 독특하고 True
을 반환 때이 인스턴스에 'melon'
이 될 것입니다 선택한 과일에 fruitChosen
의 값을 설정합니다.
'시도'블록에 표시 해 주셔서 감사합니다. – user94628