code: def greedySensorPositions(numSensors, numLocations):
    
  
    locationViewCounts = [0] * numLocations
    locationViewCountsBySensor = [[0] * numLocations
                                  for _ in xrange(numSensors)]
  
    placement = random.sample(xrange(numLocations), numSensors)
  
    while True:
      yield tuple(placement)
  
      # Update statistics.
      for sensor, location in enumerate(placement):
        locationViewCounts[location] += 1
        locationViewCountsBySensor[sensor][location] += 1
  
      # Choose the locations with the lowest view counts. Break ties randomly.
      nextLocationsRanked = sorted(xrange(numLocations),
                                   key=lambda x: (locationViewCounts[x],
                                                  random.random()))
      nextLocations = nextLocationsRanked[:numSensors]
  
      # For each sensor (in random order), choose the location that has touched
      # the least, breaking ties randomly.
      sensors = range(numSensors)
      random.shuffle(sensors)
      for sensor in sensors:
        viewCount = min(locationViewCountsBySensor[sensor][location]
                        for location in nextLocations)
        location = random.choice([x for x in nextLocations
                                  if locationViewCountsBySensor[sensor][x]
                                  == viewCount])
        nextLocations.remove(location)
        placement[sensor] = location
docs: Returns an infinite sequence of sensor placements.
  
    Each return value is a tuple of locations, one location per sensor.
  
    Positions are selected using a simple greedy algorithm. The first priority of
    the algorithm is "touch every position an equal number of times". The second
    priority is "each individual sensor should touch each position an equal number
    of times".
  
    @param numSensors (int)
    The number of sensors
  
    @param numLocations (int)
    The number of locations
  
    @return (generator of tuples)
    The next locations for each sensor. The tuple's length is `numSensors`.