Longest Common Substring Algorithm Python