bonjour jai une matrice de chaine de caractère liste de liste.je veux avoir la transposé de cette matrice.la matrice est non carrée au début donc je vais ajouter des elements "" pour la rendre carrée puis j'effectue la transformation.le probléme que j'ai une erreur index out of range au niveau de la ligne ou jecris liste7[j][i].
le résulta que je veux trouvé est le suivant:liste2=['a','e','h','m'],['b','e','i','n'],....
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
 
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()