Python Convert String To Nested Knowledge