这行得通,
0(n^2)但很容易阅读和理解。
result = [] for reference, x, y in list1: for a, b, temperature in list2: if x == a and y == b: result.append([temperature, reference])
您可以
0(n)通过遍历列表并将坐标存储为来降低复杂度,
dict如下所示:
dict1 = {} for reference, x, y in list1: dict[(x, y)] = reference dict2 = {} for x, y, temperature in list2: dict2[(x, y)] = temperature result = [] for coordinate, reference in dict1.iteritems(): temperature = dict2.get(coordinate) if temperature: result.append([temperature, reference])
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)