割り当てたものでGUIDを検索したいように見えるので、GUIDをキーではなく値にしたいと思います。...しかし、実際にはユースケースによって異なります。
# list of GUID's / Rhinoceros3d point ids
arrPts = ['D20EA4E1-3957-11d2-A40B-0C5020524153',
'1D2680C9-0E2A-469d-B787-065558BC7D43',
'ED7BA470-8E54-465E-825C-99712043E01C']
# reference each of these by a unique key
ptsDict = dict((i, value) for i, value in enumerate(arrPts))
# now `ptsDict` looks like: {0:'D20EA4E1-3957-11d2-A40B-0C5020524153', ...}
print(ptsDict[1]) # easy to "find" the one you want to print
# basically make both keys: `2`, and `1` point to the same guid
# Note: we've just "lost" the previous guid that the `2` key was pointing to
ptsDict[2] = ptsDict[1]
編集:
タプルを dict のキーとして使用する場合、次のようになります。
ptsDict = {(loc, dist, attr3, attr4): 'D20EA4E1-3957-11d2-A40B-0C5020524153',
(loc2, dist2, attr3, attr4): '1D2680C9-0E2A-469d-B787-065558BC7D43',
...
}
ご存知のように、タプルは不変であるためchange
、dict のキーを取得することはできませんが、1 つのキーを削除して別のキーを挿入することはできます。
oldval = ptsDict.pop((loc2, dist2, attr3, attr4)) # remove old key and get value
ptsDict[(locx, disty, attr3, attr4)] = oldval # insert it back in with a new key
複数の値に対する 1 つのキー ポイントを保持するには、リストまたはセットを使用して GUID を含める必要があります。
{(loc, dist, attr3, attr4): ['D20E...', '1D2680...']}