And here is an another pattern matching implementation for Python [1]. It was made for compilers construction task and may look similiar for those who has an experience with Prolog, Stratego or Refal.
And here is a toy term rewriting system [2].
[1] https://github.com/true-grue/raddsl
[2] https://github.com/true-grue/code-snippets/blob/master/ttrs....