如何在Python中查找字典数组(或字典字典)的形状或维度

如何在Python中查找字典数组(或字典字典)的形状或维度,python,arrays,dictionary,shapes,dimensions,Python,Arrays,Dictionary,Shapes,Dimensions,假设我有一系列字典: thisdict={} thisdict[0]={1: 'one', 2: "two"} thisdict[1]={3: 'three', 4:'four'} thisdict[2]={5: 'five', 6:'six'} 我怎样才能找到它的尺寸?我正在寻找(3,2)--3本字典,每本有2个条目 len(thisdict)3 np.shape(thisdict)返回() 及 np.size(thisdict)返回1 如果我通过将字典转换为数据帧 im

假设我有一系列字典:

thisdict={}
thisdict[0]={1: 'one', 2: "two"}
thisdict[1]={3: 'three', 4:'four'}
thisdict[2]={5: 'five', 6:'six'}
我怎样才能找到它的尺寸?我正在寻找(3,2)--3本字典,每本有2个条目

len(thisdict)
3

np.shape(thisdict)
返回()

np.size(thisdict)
返回1

如果我通过将字典转换为数据帧

import pandas as pd
tmp = pd.DataFrame.from_dict(thisdict)
那么

np.尺寸(tmp)
=18

np.形状(tmp)
=(6,3)

自 tmp=

这仍然不能给我我想要的

我想我能做到

len(thisdict)
后跟

len(thisdict[0])


为了得到我感兴趣的两个维度,但我认为有更好的方法。获取这两个维度的“正确”方法是什么?

如果
0
-键始终存在且所有子字典的长度相同,那么
len(thisdict)
len(thisdict[0])
没有什么问题。如果没有,你可以使用类似于

def dict_dims(mydict):
d1=len(mydict)
d2=0
对于mydict中的d:
d2=最大值(d2,长度(d))
报税表d1、d2

条目的长度是否固定?我的意思是
thisdict[0]
可以有2个条目,但是
thisdict[1]
可以有3个条目谢谢。在我的例子中,是的-字典数组中的所有字典都有相同数量的条目。