Late last night in the Tanner household, ALF was repairing his spaceship so he might get back to Melmac. Unfortunately for him, he forgot to put on the parking brake, and the spaceship took off during repair. Now it's hovering in space.

ALF has the technology to bring the spaceship home if he can lock on to its location.

Given a map:

````
..........
..........
..........
.......X..
..........
..........
````

The map will be given in the form of a string with \n separating new lines. The bottom left of the map is [0, 0]. X is ALF's spaceship.

In this example:

If you cannot find the spaceship, the result should be

```
"Spaceship lost forever."
```

Can you help ALF?


Check out my other 80's Kids Katas:


80's Kids #1: How Many Licks Does It Take
80's Kids #2: Help Alf Find His Spaceship
80's Kids #3: Punky Brewster's Socks
80's Kids #4: Legends of the Hidden Temple
80's Kids #5: You Can't Do That on Television
80's Kids #6: Rock 'Em, Sock 'Em Robots
80's Kids #7: She's a Small Wonder
80's Kids #8: The Secret World of Alex Mack
80's Kids #9: Down in Fraggle Rock 
80's Kids #10: Captain Planet

Difficulty: introductory

Starter code:

def find_spaceship(astromap):
	

Solutions:
def find_spaceship(astromap):
    lines = astromap.splitlines()
    for y, line in enumerate(lines):
        x = line.find('X')
        if x != -1:
            return [x, len(lines) - 1 - y]
    return 'Spaceship lost forever.'


def find_spaceship(astromap):
    for a, row in enumerate(reversed(astromap.split('\n'))):
        for b, col in enumerate(row):
            if col == 'X':
                return [b, a]
    return 'Spaceship lost forever.'


def find_spaceship(astromap):
    astromap = astromap.split('\n')
    astromap.reverse()
    for i in range(len(astromap)):
        if 'X' in astromap[i]:
            return [astromap[i].index('X'), i]
    return 'Spaceship lost forever.'

def find_spaceship(amap):
    a=amap.split('\n')[::-1]
    for i in a:
        if 'X' in i:
            return[ i.index('X') , a.index(i) ]
    return "Spaceship lost forever."

def find_spaceship(astromap):
    arr = astromap.split('\n')[::-1]
    for i in range(len(arr)):
        print(arr[i])
        for j in range(len(arr[i])):
            if arr[i][j] == 'X': return [j, i]
    return "Spaceship lost forever."

def find_spaceship(astromap):
    try: return next([j, i] for i,row in enumerate(reversed(astromap.split('\n'))) for j,c in enumerate(row) if c == 'X')
    except: return "Spaceship lost forever."

find_spaceship=lambda m:"Spaceship lost forever."*('X'not in m)or(lambda x=m.find('X'):[x-1-m[:x].rfind('\n'),m[x:].count('\n')])()

def find_spaceship(astromap):
    return next(([j, i]
        for i, row in enumerate(astromap.splitlines()[::-1])
        for j, x in enumerate(row)
        if x == 'X'
    ), 'Spaceship lost forever.')

from typing import List, Union


def find_spaceship(astromap: str) -> Union[List[int], str]:
    return next(([x, y] for y, r in enumerate(reversed(astromap.splitlines())) for x, c in enumerate(r) if c == 'X'),
                "Spaceship lost forever.")