Python Find Pattern In 1d Shapes