0

私はこのdictのリストを持っています

{"FieldFlags": "0", "FieldNameAlt": "Please forgive me", "FieldName": "field1", "FieldType": "Text", "FieldJustification": "Left", "FieldValue": "test"},
 {"FieldJustification": "Left", "FieldNameAlt": "Please forgive me", "FieldName": "min_speed", "FieldType": "Text", "FieldFlags": "0"},
 {"FieldJustification": "Left", "FieldNameAlt": "Please forgive me", "FieldName": "avg_speed", "FieldType": "Text", "FieldFlags": "0"}, 
 {"FieldJustification": "Left", "FieldNameAlt": "Please forgive me", "FieldName": "lowest_speed", "FieldType": "Text", "FieldFlags": "0"},
 {"FieldJustification": "Left", "FieldNameAlt": "Please forgive me", "FieldName": "air", "FieldType": "Text", "FieldFlags": "0"}, 
 {"FieldJustification": "Left", "FieldNameAlt": "Please forgive me", "FieldName": "slope", "FieldType": "Text", "FieldFlags": "0"}]

私の目的のために、私はこの配列を次のようなものに変換する必要があります

fields = [('field1','test'),('min_speed',''),('avg_speed','')..]

だから基本的に私はのタプルが欲しい (FiedName,FieldValue)

fieldValueがない場合は、空として表示されます。

どうすればそれを変換できますか

4

2 に答える 2

4
fields = [(d['FieldName'], d.get('FieldValue', '')) for d in your_list]
于 2012-12-03T01:54:33.443 に答える
0

map()を使用することもできます。

fields = map(lambda d: (d['FieldName'], d.get('FieldValue', '')), your_list)
于 2012-12-03T01:59:31.900 に答える