title: Python: Extract Key, Value Pairs From A Dictionary - Key Contains Specific Text
body: <p>I currently have a dictionary that looks like this:</p>
  
  <pre><code>{OctetString('Ethernet8/6'): Integer(1),
   OctetString('Ethernet8/7'): Integer(2),
   OctetString('Ethernet8/8'): Integer(2),
   OctetString('Ethernet8/9'): Integer(1),
   OctetString('Vlan1'): Integer(2),
   OctetString('Vlan10'): Integer(1),
   OctetString('Vlan15'): Integer(1),
   OctetString('loopback0'): Integer(1),
   OctetString('mgmt0'): Integer(1),
   OctetString('port-channel1'): Integer(1),
   OctetString('port-channel10'): Integer(1),
   OctetString('port-channel101'): Integer(1),
   OctetString('port-channel102'): Integer(1)}
  </code></pre>
  
  <p>I want my dictionary to look like this:</p>
  
  <pre><code>{OctetString('Ethernet8/6'): Integer(1),
   OctetString('Ethernet8/7'): Integer(2),
   OctetString('Ethernet8/8'): Integer(2),
   OctetString('Ethernet8/9'): Integer(1)}
  </code></pre>
  
  <p>I am not sure what is the best way to find these key, value pairs. I really want anything that matches '\Ethernet(\d*)/(\d*)'. However I am not sure the best way to go about this. My main goal is to match all the Ethernet Values and then count them. For example: After I have the dict matching all of Ethernetx/x I want to count the amount of 1's and 2's. </p>
  
  <p>Also, why do I get only Ethernet8/6 when I iterate the dictionary and print, but when I pprint the dictionary I end up with OctetString('Ethernet8/6')?</p>
  
  <pre><code>for k in snmp_comb: print k
  Ethernet2/18
  Ethernet2/31
  Ethernet2/30
  Ethernet2/32
  Ethernet8/46
  </code></pre>