What is difference between these two slicing methods and why aren't they giving the same result
11:20 25 Dec 2025

I was reading this book " Impractical python projects ", then he started talking about making a program that could extract pair-word palingrams from a dictionary of words, here is how I did it :

set_of_words = set(convertion.turn_file_to_lst("2of4brif.txt")) #converts the dictionary to a set
lst_of_palingrams = []
for word in set_of_words:
    rev_word = word[::-1]
    end = len(word)
    if len(word) > 1:
        for i in range(1, len(word)):
            if word[i:] == rev_word[:end-i] and rev_word[end-i:] in set_of_words:
                lst_of_palingrams += [[word, rev_word[end-i:]]]
            if word[:end-i] == rev_word[i:] and rev_word[:end-len(word[:end-i])] in set_of_words:
                lst_of_palingrams += [[rev_word[:end-len(word[:end-i])] , word]]

I checked his version and it was basically the same thing except for the 3rd if statement, he wrote:

if word[:i] == rev_word[end-i:] and rev_word[:end-i] in set_of_words:
                lst_of_palingrams += [[rev_word[:end-i] , word]]
python string slice