私はこのように見える口述を持っています
db = {
'ObjectID': ['-1', '6', '10', '13', '13', '13', '-1', '-1', '-1', '-1', '-1', '-1'],
'Test_value': ['25', '0,28999999', '100,00000000', 'Geometry', '126641,847400000000', '473106,185600000030', ' ', ' ', ' ', ' ', ' ', ' '],
'Has_error': ['true', 'true', 'true', 'true', 'true', 'true', 'false', 'false', 'false', 'false', 'false', 'false'],
'Message': ['Table row counts are different', 'ObjectID 6 is different for Field DIKTE_BRUGDEK', 'ObjectID 10 is different for Field RICHTING_1', 'ObjectID 13 is different for Field GEOMETRIE', 'ObjectID 13 is different for Field X', 'ObjectID 13 is different for Field Y', 'Shape types are the same', 'Feature types are the same', 'Feature class extents are the same', 'GeometryDefs are the same', 'Field properties are the same', 'Spatial references are the same'], 'Identifier': ['Table', 'FeatureClass', 'FeatureClass', 'FeatureClass', 'FeatureClass', 'FeatureClass', 'FeatureClass', 'FeatureClass', 'FeatureClass', 'GeometryDef', 'Field', 'SpatialReference'],
'Base_value': ['23', '0,19000000', '394,00000000', 'Geometry', '126530,700000000000', '473095,700000000010', ' ', ' ', ' ', ' ', ' ', ' ']}
'ObjectID'のリストのエントリに基づいて、それをより小さなサブセット、つまり-1に分割したいと思います。私の最初の試みは、次のような値のインデックスを作成することでした。
filter_ind = []
for k,v in db.iteritems():
for i in xrange(len(v)):
if (k == 'ObjectID') and (int(v[i]) != -1):
filter_ind.append(i)
次に、並べ替えフィルターとしてfilter_indを使用して、新しいdictを作成しようとしました。
dict((k,v[i]) for i in filter_ind for k, v in db.iteritems())
私が得たのはv
、もうリストではないので、最後の一致だけです:
{'ObjectID':'13','Test_value':'473106,185600000030','Has_error':'true',
'Message':'ObjectID 13 is different for Field Y',
'Identifier':'FeatureClass','Base_value': '473095,700000000010'}
質問:それ自体の特定の値に基づいてdictをフィルタリングする別の方法はありますか?これが比較的単純なアプローチと見なされる場合、新しいdictを作成するためのフィルターとしてインデックスを使用するスマートな方法は何ですか?すでにありがとう。