# KeyError on List data type

**URL:** <https://community.deeplearning.ai/t/keyerror-on-list-data-type/895332>\
**Category:** AI Python for Beginners\
**Tags:** week-module-4, coursera-platform\
**Created:** [September 28, 2026, 7:24am UTC](https://community.deeplearning.ai/t/keyerror-on-list-data-type/895332 "2026-09-28T07:24:53Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ANGELA\_RITTENHOUSE](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/angela_rittenhouse/32/167898_2.png) [@ANGELA\_RITTENHOUSE](https://community.deeplearning.ai/u/ANGELA_RITTENHOUSE)\
**Post date:** [September 28, 2026, 7:24am UTC](https://community.deeplearning.ai/t/keyerror-on-list-data-type/895332/1 "2026-09-28T07:24:53Z")

</div>

C1M4\_Assignment Ex\_2

I keep getting KeyError - the data type is List not Dictionary

I checked the data type of candy\_data, and it is a list. But I can’t seem to move forward on this exercise, and I’m not sure where the problem is

 ![Screenshot 2026-09-28 at 3.20.48 AM](https://global.discourse-cdn.com/dlai/original/3X/4/8/480474d6f02c7ee1e81ea3968caee1a94702f958.png)

**(Solution code removed, as posting it publicly is against the honour code of this community, regardless if it is correct or not. You can share the errors you get)**

---

<div class="post-metadata">

**Author:** ![bmiteva](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/bmiteva/32/128438_2.png) [@bmiteva](https://community.deeplearning.ai/u/bmiteva)\
**Post date:** [September 28, 2026, 8:15am UTC](https://community.deeplearning.ai/t/keyerror-on-list-data-type/895332/2 "2026-09-28T08:15:22Z")

</div>

The function get\_popularity\_scores is defined so that it takes the candy\_data list and extracts the Popularity Score, so you don’t need to iterate over each row of the data. Per the instructions, you should "#Use ‘get\_popularity\_scores’ and pass in the lst `candy_data".` So you should use the function get\_popularity\_scores directly in the format function\_name(list\_name), on the same line as “#Add your code here”. Please let me know if this helps.

---

<div class="post-metadata">

**Author:** ![ANGELA\_RITTENHOUSE](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/angela_rittenhouse/32/167898_2.png) [@ANGELA\_RITTENHOUSE](https://community.deeplearning.ai/u/ANGELA_RITTENHOUSE)\
**Post date:** [September 28, 2026, 1:29pm UTC](https://community.deeplearning.ai/t/keyerror-on-list-data-type/895332/3 "2026-09-28T13:29:36Z")

</div>

Thank you, it works.

---

<div class="post-metadata">

**Author:** ![Mubsi](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/mubsi/32/94983_2.png) [@Mubsi](https://community.deeplearning.ai/u/Mubsi)\
**Post date:** [September 29, 2026, 5:38pm UTC](https://community.deeplearning.ai/t/keyerror-on-list-data-type/895332/4 "2026-09-29T17:38:07Z")

</div>


