Untitled
unknown
plain_text
a year ago
3.5 kB
4
Indexable
Never
from itertools import permutations sample_list = ['Oslo', 'Arendal','Grimstad','Halden','Kristiansand','Porsgrunn','Tromsø','Trondheim','Tønsberg'] list_combinations = list(permutations(sample_list)) final_list = [] for elem in list_combinations: if elem[0] == 'Oslo': final_list.append(elem) minutesOslo = {"Arendal": 184, "Grimstad": 194, "Halden": 85, "Kristiansand": 225 ,"Oslo": 0, "Porsgrunn": 113, "Tromsø": 1349 , "Trondheim": 388, "Tønsberg": 77} minutesArendal={"Arendal":0, "Grimstad":22, "Halden":224, "Kristiansand":48 ,"Oslo":184, "Porsgrunn": 82, "Tromsø":1500, "Trondheim": 569, "Tønsberg":119} minutesGrimstad={"Arendal":22, "Grimstad":0, "Halden":236, "Kristiansand":35,"Oslo":194, "Porsgrunn": 94, "Tromsø":1500, "Trondheim": 579, "Tønsberg":130} minutesHalden={"Arendal":224, "Grimstad":236, "Halden":0, "Kristiansand":264,"Oslo":85,"Porsgrunn": 155,"Tromsø":1423, "Trondheim": 458, "Tønsberg":121} minutesKristiansand={"Arendal": 48, "Grimstad":35, "Halden":264, "Kristiansand":0,"Oslo":225, "Porsgrunn": 123, "Tromsø":1560, "Trondheim": 604, "Tønsberg":159} minutesOslo={"Arendal":184, "Grimstad":194, "Halden":85, "Kristiansand":225,"Oslo":0, "Porsgrunn": 113, "Tromsø":1349, "Trondheim": 388, "Tønsberg":77} minutesPorsgrunn={"Arendal": 82, "Grimstad":94, "Halden":155, "Kristiansand":123,"Oslo":113, "Porsgrunn": 0, "Tromsø":1440, "Trondheim": 489, "Tønsberg":49} minutesTromsø={"Arendal": 1500, "Grimstad":1500, "Halden":1423, "Kristiansand":1560 ,"Oslo":1349, "Porsgrunn": 1440, "Tromsø":0, "Trondheim": 1010, "Tønsberg":1412} minutesTrondheim={"Arendal":569, "Grimstad":579, "Halden":458, "Kristiansand":604,"Oslo":388, "Porsgrunn": 489, "Tromsø":1010, "Trondheim": 0, "Tønsberg":453} minutesTønsberg={"Arendal":119, "Grimstad":130, "Halden": 121 ,"Kristiansand":159 , "Oslo": 77, "Porsgrunn":49, "Tromsø": 1412, "Trondheim": 453, "Tønsberg":0} #print(list_combinations) shortest = [5000] for index, el in enumerate(final_list): # print(index, el) minutes = 0 minutes += minutesOslo[el[1]] for number in range(1,8): if el[number] == "Arendal": minutes += minutesArendal[el[number+1]] if el[number] == "Grimstad": minutes += minutesGrimstad[el[number+1]] if el[number] == "Halden": minutes += minutesHalden[el[number+1]] if el[number] == "Kristiansand": minutes += minutesKristiansand[el[number+1]] if el[number] == "Porsgrunn": minutes += minutesPorsgrunn[el[number+1]] if el[number] == "Tromsø": minutes += minutesTromsø[el[number+1]] if el[number] == "Trondheim": minutes += minutesTrondheim[el[number+1]] if el[number] == "Tønsberg": minutes += minutesTønsberg[el[number+1]] if el[8] == "Arendal": minutes += minutesArendal["Oslo"] if el[8] == "Grimstad": minutes += minutesGrimstad["Oslo"] if el[8] == "Halden": minutes += minutesHalden["Oslo"] if el[8] == "Kristiansand": minutes += minutesKristiansand["Oslo"] if el[8] == "Porsgrunn": minutes += minutesPorsgrunn["Oslo"] if el[8] == "Tromsø": minutes += minutesTromsø["Oslo"] if el[8] == "Trondheim": minutes += minutesTrondheim["Oslo"] if el[8] == "Tønsberg": minutes += minutesTønsberg["Oslo"] # print(index, minutes) if shortest[0] > minutes: shortest.insert(0, minutes) print("Raskeste: ", shortest[0])