不废话了,直接上代码
def zjh_print(temp, indent=0):
if type(temp) == dict:
for key, value in temp.items():
print('')
print('|'*indent, end='')
print(key, end='')
zjh_print(value, indent + 1)
elif type(temp) == list:
# for data in temp:
print('->list', end='')
print('|'*(indent-1), end='')
zjh_print(temp[0], indent)
我手上的一个这样的嵌套体,
zjh_print(artist_dict)
输出结果如下(首行为空行)
name
mbid
streamable
ontour
listeners
playcount
bio_published
bio_summary
bio_content
similar_artists->list
|name
|mbid
|match
|streamable
tags->list
|name
|count
tracks->list
|name
|play count
|listeners
|mbid
|streamable
|rank