![在此处输入图像描述] [1]考虑以下代码,我想根据GRADUEL顺序中的偶数列表索引对奇数列表索引进行排序。
Processes = input(" Enter the processes times & arrival times separated by a comma: ")
BurstTimes = Processes[::2]
ArrivalTimes = Processes[1::2]
答案 0 :(得分:1)
list1, list2 = [5, 4, 7, 1, 9], [3, 1, 10, 11, 5]
indices1 = range(len(list1))
indices1.sort(key=lambda x: list2[x])
list1 = map(lambda i: list1[i], indices1)
print list1, list2
给出:
[4, 5, 9, 7, 1] [3, 1, 10, 11, 5]
答案 1 :(得分:0)
这看起来像你想要的
processes = [12, 24, 36, 27, 45, 29, 35, 78, 23, 13]
burst_times = processes[::2]
arrival_times = processes[1::2]
zipped_set = zip(arrival_times,burst_times)
result_set = zip(*sorted(zipped_set))
result_set[1]
...(23, 12, 36, 45, 35)
链接到小提琴http://repl.it/R6N 随意在小提琴中使用自己的例子