不廢話了,直接上代碼
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