Problème avec les liste de liste

Résolu/Fermé
Utilisateur anonyme - Modifié par jowatedefuc le 16/02/2016 à 16:51
 Utilisateur anonyme - 8 mars 2016 à 02:41
j'ai finis un logiciel mais une fonction me cause problème
j'ai mis plein de print, j'ai isolé la fonction et j'ai réduis la grosseur de la liste mais même la je ne comprend pas ou est le probleme et comment je peut le regler
lofl=list of list

def SetCoor(lofl, coor, value):
	print('coor:',coor)
	print('value:',value)
	print()
	for line in lofl:
		print(line)
	
	lofl[ coor['x'] ][ coor['y'] ]=value
	
	print()
	for line in lofl:
		print(line)
	return(lofl)

lofl=[['wall']*4]*4
coor={'x':2, 'y':1}
value='willpath'
lofl=SetCoor(lofl, coor, value)

affiche:

coor: {'x': 2, 'y': 1}
value: willpath

['wall', 'wall', 'wall', 'wall']
['wall', 'wall', 'wall', 'wall']
['wall', 'wall', 'wall', 'wall']
['wall', 'wall', 'wall', 'wall']

['wall', 'willpath', 'wall', 'wall']
['wall', 'willpath', 'wall', 'wall']
['wall', 'willpath', 'wall', 'wall']
['wall', 'willpath', 'wall', 'wall']

svp AIDEZ MOI

2 réponses

Utilisateur anonyme
16 févr. 2016 à 17:08
pourquoi je ne peut pas faire
liste_de_liste=fonction(liste_de_liste)
j'aimerais trouver comment regler le probleme de facon plus elegante que
liste_de_liste2=eval(ascii(liste_de_liste))
liste_de_liste=fonction(liste_de_liste2)
0
Utilisateur anonyme
18 févr. 2016 à 19:04
Salut,

Je ne comprend pas ton problème.

La variable lofl est globale (car non définie dans une fonction mais dans le corps du programme. Tu n'as même pas besoin de la mettre en paramètre de ta fonction parce que ça sera modifier direct.
0
Utilisateur anonyme
5 mars 2016 à 21:52
la raison de ça c'est quoi
['wall', 'wall', 'wall', 'wall']
['wall', 'wall', 'wall', 'wall']
['wall', 'wall', 'wall', 'wall']
['wall', 'wall', 'wall', 'wall']

['wall', 'willpath', 'wall', 'wall']
['wall', 'willpath', 'wall', 'wall']
['wall', 'willpath', 'wall', 'wall']
['wall', 'willpath', 'wall', 'wall']
plz
0
a = [[1]*2]*2
l = [[1, 1], [1, 1]]

a[1][1] = 2
l[1][1] = 2

print(a)
print(l)


http://sametmax.com/valeurs-et-references-en-python/
0
Utilisateur anonyme
8 mars 2016 à 02:41
cool vraiment pour les erreurs c'est la meilleur page ;)
0