title: How to overload the subscript operator with swig Python
body: <p>I have a class which contains a <code>std::vector&lt;Foo&gt;</code> where <code>Foo</code> is a class containing a key, value, comment, etc. Please note that there is a reason why I am using a vector and not a dictionary.</p>
  
  <p>I have overloaded the subscript operator in C++ such that <code>foos["Key Name"]</code> will search through the vector for a Foo object with key matching "Key Name" (where <code>foos</code> is a <code>std::vector&lt;Foo&gt;</code>).</p>
  
  <p>I use <a href="http://en.wikipedia.org/wiki/SWIG" rel="nofollow">SWIG</a> to create a Python wrapper for my library, and I would really like for this subscript operator to extend into Python. In other words, I want to be able to use the <code>foos["Key Name"]</code> for finding objects in the vector in Python.</p>
  
  <p>Any tips on how to make SWIG recognize the subscript operator and overload it in Python? I am a little surprised that I couldn't find examples of people doing this online. I guess most people just use a <code>std::map</code> and have SWIG convert it to a Python <code>dict</code>.</p>