salut jai une matrice(liste de liste) je veux récupérer la transposé de cette matrice.jai ecrit un peti programme mais il y a une erreur list index out of range jai pas su comment la résoudre.le probléme dans la lignes ou il ya liste7[j][i]
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 import sys import re def main(): liste7=[['a','b','c'],['d','e','f','j'],['h','i'],['m','n','o','p','k','l']] liste=[] for i in range(len(liste7)): for j in range(len(liste7)): liste.append(len(liste7[j])) max=0 for i in range(len(liste)): if liste[i]>max: max=liste[i] indice_max=i print "le max",max for i in range(len(liste7)): if (len(liste7[i])<max): print "inf a max",len(liste7[i]) diff=max-len(liste7[i]) for k in range(diff): liste7[i].append("") print liste7 for i in range(len(liste7)): print len(liste7[i]) liste2=[] for i in range(len(liste7)-1): for j in range(len(liste7[i])-1): print liste7[i][j] liste2.append(liste7[j][i]) print liste2 liste2=[] main()
Partager