Dictionaries are unordered collection of items that are stored and fetched by key!
c={} dictionary
c=[] list
c=dict(enumerate(set(open('/home/lmarches/cvpr13/visual/features_ml/lists_mlfu300/class.txt').read().split())))
set = get unique elements
enumerate = generate the sequence
dict= assembles the dictionary
433: 'you_need',
434: 'your_camera',
435: 'your_entry',
value, key
if you want to invert :
;c_inv= dict([(value, key) for (key, value) in c.iteritems()] )
'you_need': 433
'your_camera', 434
'your_entry', 435
if you want to search by value
[key for key,value in c.items() if value=='your_entry' ][0]
435
No comments:
Post a Comment