首页 > 解决方案 > 嵌套字典有问题

问题描述

我在嵌套字典的这一部分遇到了一些麻烦。我尝试了很多不同的东西,但我不断收到这个错误:

complete_dict[county]['price'] = int(item.get(average_price))
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'

这是我到目前为止的说明和代码。

    # Finally you will find how much the housing prices have changed in each county.
    # You can get this number by finding the difference between the average home price
    # in April 1996 and the average home price in April 2015.
    # The values should mostly be positive since home prices have increased since 1996.
    # We are expecting to see float values.

    # todo Put code here to find the housing prices.
    for item in home_data:
        price = int(item.get('Home Price', 0))
        county = item.get('county')
    if county in complete_dict:
       price1 = complete_dict[county].get('price', 0)
       average_price = price1-price
       complete_dict[county]['price'] = int(item.get(average_price))
    else:
       complete_dict[county] = {'price': int(price)}

以下是关于 complete_dict 的更多说明: 字典创建 # 使用县名作为键创建字典。# 从医院数据集中,您将要添加一个县的所有 total_licensed_beds。# 从 COVID 数据集中,您将要添加活动案例。# 从 Housing 数据集中,您将需要房价之间的差异(2015 - 1996)。# 你的数据结构如下所示: # {'county1': {'beds': [1], 'cases': [2], 'housing': [3]}, 'county2': {'beds': [1],“案例”:[2],“住房”:[3]}}

标签: pythondictionary

解决方案


推荐阅读