Python neighbour code