Find words in a word grid I made a program to find words in a word grid. It will find words that are horizontal, vertical, positive sloped and vertical sloped, all in both forwards and backwards.
Here is my code:
with open('grid.txt', 'r') as f:
    lst = [[a for a in l.strip() if a != ' ' and a!= '\n'] for l in f.readlines() if l] # Convert file to a nested list, with all whitespaces removed
    lst2 = [a[::-1] for a in zip(*lst)] # Create another nested list that is the first nested list rotated 90 degrees clockwise
    
height = len(lst) # Height of grid
width = len(lst[0]) # Width of grid

while True:
    
    word = input(&quot;Input your word: &quot;) # Word to find

    # Find horizontal word
    for l in lst:
        w = ''.join(l)
        if word in w or word in w[::-1]:
            print(w)
            print('Horizontal!')

    # Find vertical word
    for l in lst2:
        w = ''.join(l)
        if word in w or word in w[::-1]:
            print(w)
            print('Vertical!')

    # Find Negative slope
    for i in range(width):
        w = ''
        for j in range(height):
            try:
                w += lst[j][i]
                i += 1
            except:
                break
        if word in w or word in w[::-1]:
            print(w)
            print('Negative Slope!')

    for i in range(height):
        w = ''
        for j in range(width):
            try:
                w += lst[i][j]
                i += 1
            except:
                break
        if word in w or word in w[::-1]:
            print(w)
            print('Negative Slope!')

    # Find positive slope
    for i in range(height):
        w = ''
        for j in range(width):
            try:
                w += lst2[j][i]
                i += 1
            except:
                break
        if word in w or word in w[::-1]:
            print(w)
            print('Positive Slope!')
        
    for i in range(width):
        w = ''
        for j in range(height):
            try:
                w += lst2[i][j]
                i += 1
            except:
                break
        if word in w or word in w[::-1]:
            print(w)
            print('Positive Slope!')


Here is my grid.txt:
n x b z t a ê s e y m t w u e r r
y s j q l n o i l f k j c y h t a
q x n e z d l g v r x y x a p u a
b b k à a y e g q i h u x b q e u
m h z x r é q m x m e l t i b t q
i k i g c j c h w l w i ï t p u o
i s o w u w m a p z a b w g d e p
i p s g u y n n j i j f o f n w l
l i u l ô i e j b e o t s e b c j
y m f v f e v h f c p r d m y v n
f w h v d t z y i x t e e u v n e
e w x e h l x n q m s n p z e f b
e j l v r x ç t d b i a z v d h z
c i i n s s i b s t o q o d d k x
z o f c a w b j b l m w k f e i s

I feel like my code is unnecessarily long for a rather simple task.
Are there any ways to shorten and improve it?
Catch invalid input
When I was trying out your code, I entered Cntrl + Z which crashed the program. Using Try and Except can prevent this from happening
try:
    word = input(&quot;Enter your word:&quot;)
except Exception:
    print(&quot;Invalid input!&quot;)


Also, I'd keep a check of len(word) == 0 since an empty input is dangerous too


Reading grid.txt
with open('grid.txt', 'r') as f:
    lst = [[a for a in l.strip() if a != ' ' and a!= '\n'] for l in f.readlines() if l] 
    lst2 = [a[::-1] for a in zip(*lst)]

You can greatly simplify this part by using list.split()
with open('grid.txt', 'r') as f:
    lst = [line.split() for line in f.readlines()]
    lst2 = list( zip (*lst[::-1]) )

If you're worried about the '\n' at the end, the new lists using this method will not have it.

I'd suggest you keep the names of the lists as horizontal and vertical rather than lst and lst2 which don't mean much

Split work into functions
You should separate tasks into functions so that there isn't one huge block of code that does everything. Moreover, splitting work into functions makes it easy to maintain your code. What if your main game loop could look like this
def game_loop():
    while True:
        word = take_input()
        matches = find_matches(grid,word)

        if matches == None: print(&quot;No matches&quot;)
        else:
            for match in matches:
                print( &quot;Match: &quot; + match )

        if input(&quot;Do you want to play again? (y/n): &quot;).lower() == 'n':
            break

An alternate approach
The reason your code isn't as efficient as the method I will just show you is that you repeatedly reverse the lists and use a lot of loops. There is a much better and cleaner way in which you need to go through the whole grid only once.

Read the .txt file into a list ( like we previously did for lst)
Start by going through each element in the 2-D list
If the element matches the first character of the entered word, check all 8 directions to complete the match

Implementaion