计算列表的长度 [英] Count the length of list

查看:478
本文介绍了计算列表的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算列表的长度。我有以下文件

How can I count the length of list. I have following file

[0 1 2]

[0 1 2]

[0]

[0 1 2]

[0 1 2]

[0]

在上面的例子中,第一个列表应该打印3等等。 >

In above example the first list should print 3 and so on

推荐答案

假设你的整个JSON字符串格式正确(例如我没有检查它,因为它很长)这个:

Assuming your entire JSON string is in proper format (e.g. I didn't check it all since it's pretty long) you can load it like this:

import json
json_data=open('json_data')

data = json.load(json_data)
print(data)
json_data.close()

然后引用JSON的不同部分,像这样:

And then to reference different parts of the JSON like so:

data["resouceId"]
data["properties"]["title"]
# etc...



h1>

如果你想得到所有的 resourceId ,那么你可以试试:

for key, value in data.items():
    if key == "resourceId":
        print(value)

这篇关于计算列表的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆