Dans votre message du 9 janvier à 7h35, à quoi correspond cette ligne ?
Code : Tout sélectionner
if element[0] != gare[0] and element[2] == gare[2]:
Merci encore.
Code : Tout sélectionner
if element[0] != gare[0] and element[2] == gare[2]:
Code : Tout sélectionner
import csv
import geopy.distance as gd
with open('lignes-par-type.csv',newline='',encoding='utf-8') as f :
lire = csv.reader(f)
liste = [ligne for ligne in lire]
liste_lignes = liste[1:]
lignes_debut_fin=[int(ligne[0]) for ligne in liste_lignes]
with open('liste-des-gares.csv',newline='',encoding='utf-8') as h :
extraction = csv.reader(h)
liste_brute = [ligne for ligne in extraction]
liste_brute = liste_brute[1:]
liste_gares = [[int(ligne[0]),ligne[1],int(ligne[4]),float(ligne[15]),float(ligne[16])] for ligne in liste_brute if ligne[2]=='O' and ligne[15] != '']
def distance(point1,point2):
return gd.distance(point1, point2).kilometers
def graphe_lignes() :
dico={}
numero_lignes = lignes_debut_fin
for gare in liste_gares :
liste = []
for element in liste_gares :
if element[0] != gare[0] and element[2] == gare[2]:
liste.append((element[1],distance((gare[3],gare[4]),(element[3],element[4])),element[2]))
if gare[1] in dico.keys():
dico[gare[1]] = dico[gare[1]] + liste
else :
dico[gare[1]] = liste
return dico
def dico_lignes() :
dico={}
for gare in liste_gares :
dico_noeud = {}
for element in liste_gares :
if element[0] != gare[0] and element[2] == gare[2]:
dico_noeud[element[1]] = (distance((gare[3],gare[4]),(element[3],element[4])),element[2])
if gare[1] in dico.keys():
dico[gare[1]].update(dico_noeud)
else :
dico[gare[1]] = dico_noeud
return dico
def liste_lignes(gare):
liste = []
for element in liste_gares :
if element[1] == gare and element[2] not in liste :
liste.append(element[1])
return liste
Code : Tout sélectionner
if element[0] != gare[0] and element[2] == gare[2]
Code : Tout sélectionner
import csv
with open('lignes-par-type.csv',newline='',encoding='utf-8') as f :
lire = csv.reader(f,delimiter = ";")
liste = [ligne for ligne in lire]
liste_lignes = liste[1:]
lignes_debut_fin=[int(ligne[0]) for ligne in liste_lignes]
with open('liste-des-gares.csv',newline='',encoding='utf-8') as h :
extraction = csv.reader(h,delimiter = ";")
liste_brute = [ligne for ligne in extraction]
liste_brute = liste_brute[1:]
liste_gares = [[int(ligne[4]),ligne[1],int(ligne[6][:3]),float(ligne[13]),float(ligne[14])] for ligne in liste_brute if ligne[2]=='O' and ligne[15] != '']
myDict = {}
for element in liste_gares:
if element[0] in myDict:
myDict[element[0]].append([element[1],element[2]])
else:
myDict[element[0]] = [[element[1], element[2]]]
Code : Tout sélectionner
>>>chaine="347+678"
>>> nombre = int(chaine.split("+")[0]
>>> nombre
347
Code : Tout sélectionner
import csv
with open('lignes-par-type.csv',newline='',encoding='utf-8') as f :
lire = csv.reader(f,delimiter = ";")
liste = [ligne for ligne in lire]
liste_lignes = liste[1:]
lignes_debut_fin=[int(ligne[0]) for ligne in liste_lignes]
with open('liste-des-gares.csv',newline='',encoding='utf-8') as h :
extraction = csv.reader(h,delimiter = ";")
liste_brute = [ligne for ligne in extraction]
liste_brute = liste_brute[1:]
liste_gares = [[int(ligne[4]),ligne[1],int(ligne[6].split("+")[0]),float(ligne[13]),float(ligne[14])] for ligne in liste_brute if ligne[2]=='O' and ligne[15] != '']
myDict = {}
for element in liste_gares:
if element[0] in myDict:
myDict[element[0]].append([element[1],element[2]])
else:
myDict[element[0]] = [[element[1], element[2]]]
Code : Tout sélectionner
abs(int(chaine1.split("+")[0] - int(chaine2.split("+")[0])
Code : Tout sélectionner
def conversion(chaine):
if "+" in chaine :
return int(chaine.split("+")[0])
elif "-" in chaine:
return int(chaine.split("-")[0])
Code : Tout sélectionner
liste_gares=[[int(ligne[4]),ligne[1],conversion(ligne[6]),float(ligne[13]),float(ligne[14])] for ligne in liste_brute if ligne[2]=='O' and ligne[15] != '']
Code : Tout sélectionner
import csv
with open('liste-des-gares.csv',newline='',encoding='utf-8') as h :
extraction = csv.reader(h,delimiter = ";")
liste_brute = [ligne for ligne in extraction]
liste_brute = liste_brute[1:]
liste_gares = [[int(ligne[4]),ligne[1],int(ligne[6][:3]),float(ligne[13]),float(ligne[14])] for ligne in liste_brute if ligne[2]=='O' and ligne[15] != '']
myDict = {}
for element in liste_gares:
if element[0] in myDict:
myDict[element[0]].append([element[1],element[2]])
else:
myDict[element[0]] = [[element[1], element[2]]]
Code : Tout sélectionner
myDict[340000]
[['Bonnières', 68], ['Rosny-sur-Seine', 62], ['Sotteville', 133], ['Les Mureaux', 40], ["Pont-de-l'Arche", 118], ['Oissel', 125], ['St-Étienne-du-Rouvray', 129], ['Poissy', 25], ['Paris-Batignolles', 2], ['Vernouillet-Verneuil', 34], ['Le Havre', 227], ['Bréauté-Beuzeville', 202], ['Gaillon-Aubevoye', 93], ['Motteville', 169], ['Rouen-Rive-Droite', 139], ['St-Pierre-du-Vauvray', 106], ['Mantes-la-Jolie', 57]]
Code : Tout sélectionner
def conversion(chaine):
if "+" in chaine :
return float(chaine.split("+")[0]+"."+chaine.split("+")[1])
elif "-" in chaine:
return float(chaine.split("-")[0]+"."+chaine.split("-")[1])
Code : Tout sélectionner
import csv
def conversion(chaine):
if "+" in chaine :
return float(chaine.split("+")[0]+"."+chaine.split("+")[1])
elif "-" in chaine:
return float(chaine.split("-")[0]+"."+chaine.split("-")[1])
with open('liste-des-gares.csv',newline='',encoding='utf-8') as h :
extraction = csv.reader(h,delimiter = ";")
liste_brute = [ligne for ligne in extraction]
liste_brute = liste_brute[1:]
liste_gares = [[int(ligne[4]),ligne[1],conversion(ligne[6]),float(ligne[13]),float(ligne[14])] for ligne in liste_brute if ligne[2]=='O' and ligne[15] != '']
myDict = {}
for element in liste_gares:
if element[0] in myDict:
myDict[element[0]].append([element[1],element[2]])
else:
myDict[element[0]] = [[element[1], element[2]]]
def dico_lignes() :
dico={}
for gare in liste_gares :
dico_noeud = {}
for element in liste_gares :
if element[0] != gare[0] and element[2] == gare[2]:
dico_noeud[element[1]] = ((gare[3]-element[3]),element[2])
if gare[1] in dico.keys():
dico[gare[1]].update(dico_noeud)
else :
dico[gare[1]] = dico_noeud
return dico
Code : Tout sélectionner
dico_lignes()['Poitiers']
Code : Tout sélectionner
>>> dico_lignes()['Poitiers']
{'Choisy-le-Roi': (288.31991504994414, 570000), 'Chasseneuil (Vienne)': (8.31988
6268217884, 570000), 'La Tricherie': (18.236657224121828, 570000), 'Couhé-Vérac'
: (31.36764976530626, 570000), 'Ingrandes-sur-Vienne': (37.18536118986929, 57000
0), 'Blois-Chambord': (134.51359631523687, 570000), 'Ste-Maure-Noyant': (61.6790
4111566583, 570000), 'Vitry-sur-Seine': (291.3420186256925, 570000), 'Bassens-Ap
pontements': (198.49483105097934, 570000), 'Mer': (153.37912365673137, 570000),
'St-Saviol': (49.19431944182391, 570000), 'Jaunay-Clan': (11.693805638496023, 57
0000), 'Étampes': (247.72759688254214, 570000), 'Villeperdue': (72.5962886928164
9, 570000), 'St-Pierre-des-Corps': (94.1770123591242, 570000), 'Bordeaux-St-Jean
': (207.12281456648523, 570000), 'Toury': (216.20935633673622, 570000), 'Angoulê
me': (104.05048584841529, 570000), 'Villeneuve-le-Roi': (286.6743109871476, 5700
00), 'Port-de-Piles': (51.7179170219756, 570000), 'Naintré-les-Barres': (23.3178
0658271575, 570000), 'Paris-Tolbiac': (293.24408223947177, 570000), 'Artenay': (
203.56063314619325, 570000), 'La Couronne': (110.11212122770999, 570000), 'Vayre
s': (194.04882289849718, 570000), 'Les Aubrais-Orléans': (191.02592168312262, 57
0000), 'Les Ormes-sur-Vienne': (48.117330418469265, 570000), 'Coutras': (175.542
0357221762, 570000), 'Charmant': (121.18151952888114, 570000), 'Juvisy': (280.18
385400846967, 570000), 'Châtellerault': (31.048259270027653, 570000), 'Libourne'
: (190.458759019474, 570000), 'Brétigny': (269.2473899443639, 570000), 'St-Jean-
de-Sauves': (30.518804231117624, 574000)}