Generate All Substring Leetcode Python