# Introduction:
Reversi is a game usually played by 2 people on a 8x8 board.
Here we're only going to consider a single 8x1 row.
Players take turns placing pieces, which are black on one side and white on the
other, onto the board with their colour facing up.  If one or more of the
opponents pieces are sandwiched by the piece just played and another piece of
the current player's colour, the opponents pieces are flipped to the
current players colour.
Note that the flipping stops when the first piece of the player's colour is reached.
# Task:
Your task is to take an array of moves and convert this into a string
representing the state of the board after all those moves have been played.
# Input:
The input to your function will be an array of moves.
Moves are represented by integers from 0 to 7 corresponding to the 8 squares on the board.
Black plays first, and black and white alternate turns.
Input is guaranteed to be valid. (No duplicates, all moves in range, but array may be empty)
# Output:
8 character long string representing the final state of the board.
Use '*' for black and 'O' for white and '.' for empty.
# Examples:
```python
  reversi_row([])      # '........'
  reversi_row([3])     # '...*....'
  reversi_row([3,4])   # '...*O...'
  reversi_row([3,4,5]) # '...***..'
```
def reversi_row(moves):
  stones = [set(), set()]
  
  for i, p in enumerate(moves):
    curr, oppn = stones[i%2], stones[(i+1)%2]
    curr.add(p)
    
    l, r = p-1, p+1
    while l in oppn: l-=1
    while r in oppn: r+=1
    flip = set(range(l+1 if l in curr else p+1, r if r in curr else p))
    
    oppn -= flip
    curr |= flip
  
  return ''.join('*' if i in stones[0] else 'O' if i in stones[1] else '.' for i in range(8))
def reversi_row(moves):
  stones = [set(), set()]
  
  for i, p in enumerate(moves):
    curr, oppn = stones[i%2], stones[(i+1)%2]
    curr.add(p)
    
    l, r = p-1, p+1
    while l in oppn: l-=1
    while r in oppn: r+=1
    flip = set(range(l+1 if l in curr else p+1, r if r in curr else p))
    
    oppn -= flip
    curr |= flip
  
  return ''.join('*' if i in stones[0] else 'O' if i in stones[1] else '.' for i in range(8))