-3

I have below dictionary. I need to drop OS::<name> from this dictionary (In this case first 3 key,value pairs). I am only interested in the rest of the key,value pairs. How can I achieve this? It would help if I can get the logic to be as short as possible.

{u'OS::project_id': u'xyz', 
u'OS::stack_id': u'xyz', 
u'OS::stack_name': u'XYZ', 
u'image': u'RHEL-7.2', 
u'private_network_id': u'xyz', 
u'floating_ip': u'xyz', 
u'volume_type': u'ceph_fake', 
u'volume_size': u'10', 
u'key': u'my_key', 
u'flavor': u'm1.small'}
Heenashree Khandelwal
  • 659
  • 1
  • 13
  • 30

1 Answers1

1

use dict comprehension.

{key: value for key, value in d.iteritems()  if not key.startswith('OS::')}

{u'flavor': u'm1.small',
 u'floating_ip': u'xyz',
 u'image': u'RHEL-7.2',
 u'key': u'my_key',
 u'private_network_id': u'xyz',
 u'volume_size': u'10',
 u'volume_type': u'ceph_fake'}
Vishnu Upadhyay
  • 5,043
  • 1
  • 13
  • 24