我有這個串列,但我想使用“file_type”、“access_time”、“modification_time”、“blocksize”和“path”鍵。如何從串列中獲取這些值,以便將每個值放入變數中?
這個串列對應于某個檔案的資訊請求的回傳,我需要從特定的鍵中獲取特定的值并將它們存盤在一個變數中。
list = [{'group': u'supergroup', 'permission': 420, 'file_type': 'f', 'access_time': 1367317324982L, 'block_replication': 1, 'modification_time': 1367317325346L, 'length': 6783L, 'blocksize': 134217728L, 'owner': u'wouter', 'path': '/Makefile'}]
我需要從每個鍵中剝離值并將它們插入一個變數中,以便我可以更好地使用它們。
例如:
access = access_time value
modification = modification_time value
等等
uj5u.com熱心網友回復:
list_of_dicts = [YOUR DATA HERE]
for d in list_of_dicts:
file_type = d['file_type']
access_time = d['access_time']
modification_time = d['modification_time']
blocksize = d['blocksize']
path = d['path']
# do your stuff here, for each dict in your starting list
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/339422.html
