drincruz
BAN USERI think I would need more details on the question. But, I think I understand the question enough. I unfortunately can't find a solution other than this quadratic one. But here's a solution in Python:
def find_max_range(data):
sorted(data)
max_range = [data[0], data[0] + 1]
max_elems = 0
lower, upper = data[0], data[0] + 1
while upper <= data[-1]:
tmp_count = 0
for n in data:
if n >= lower and n <= upper:
tmp_count += 1
if n > upper:
break
if tmp_count > max_elems:
max_elems = tmp_count
max_range[0] = lower
max_range[1] = upper
lower += 0.1
upper += 0.1
return max_range
This should do it in Python:
# Assuming data is a list of lists
data = [
['MUC', 'LHR'],
['CDG', 'MUC'],
['SFO', 'SJC'],
['LHR', 'SFO']
]
def flatten(data):
destinations = [d[1] for d in data]
beginning = [x[0] for x in data if x[0] not in destinations][0]
itinerary = {x[0]: x[1] for x in data}
cities = set(city for flight in data for city in flight)
output = [beginning, ]
while len(output) != len(cities):
last = output[-1]
output.append(itinerary[last])
return output
If I understand the answer properly, we will be getting a frequency of each query and we will use that as weighting for which query to return. In Python, I have made the assumption that the data is formatted as a list of tuples where the tuple contains the query and the count. E.g. [('dog', 5), ('cat', 7), ('cow', 2)]
- drincruz June 16, 2015