-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththomas.py
51 lines (44 loc) · 1.45 KB
/
thomas.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*-coding:UTF8 -*
from math import *
def lectureFichier(filepath):
mon_fichier = open(filepath, "r")
contenu = mon_fichier.read()
contenu = contenu.split("\n")
contenu.pop(0)
contenu.pop(len(contenu)-1)
for i in range(0,len(contenu)):
contenu[i] = contenu[i].split(" ")
contenu[i].insert(0,i)
resultat, indice = mergeVertical(contenu)
#print(resultat);print(indice)
return resultat, indice
def mergeVertical(liste):
indice1 = -1
result = list()
tabIndice = list()
for i in range(0,len(liste)):
if liste[i][1] == 'V':
if indice1 == -1:
indice1 = i
tmp = liste[i][3:]
else :
tmp = tmp + liste[i][3:]
merge = list(set(tmp))
merge.insert(0,len(merge))
result.append(merge)
tabIndice.append([indice1,i])
tmp =[]
indice1 = -1
else:
result.append(liste[i][2:])
tabIndice.append([liste[i][0]])
return result, tabIndice
def ecritureFichier(filePath, slides, indice):
mon_fichier = open(filePath, "w")
mon_fichier.write(str(len(slides))+"\n")
for i in slides:
if len(indice[i]) ==1:
mon_fichier.write(str(indice[i][0])+"\n")
else :
mon_fichier.write(str(indice[i][0])+" " +str(indice[i][1])+"\n")
#print(lectureFichier("a_example.txt"))