Pattern matching for python