Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

python - Unable to properly find the number of sublists within a list

I have this list:

 x = [[[595.5  92.5  72.1]
     [253.5 274.5  88.1]
     [433.5  94.5  75.8]
     [458.5 276.5  85.3]
     [132.5  93.5  58.8]
     [764.5  92.5  79.6]
     [666.5 277.5  93.5]
     [275.5  92.5  67.7]]]

When I do len(x) it gives me 1, but we have 8 lists. I don't understand why, How do I get the value 8?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
len(x[0])

Since you want to get the 1st dimension length

In other words, len(x) gives number of items at 0th dimension For e.g.

> x=1,2
> len(x)
2
> x=1,2,3
> len(x)
3

To get the number of rows in the first item

len(x[0])

To get the number of columns in the first item and first row

len(x[0][0])

To get the number of columns in the first item and second row

len(x[0][1])

So on and so forth


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...