Problème avec les liste de liste

Résolu
Utilisateur anonyme -  
 Utilisateur anonyme -
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

  1. Utilisateur anonyme
     
    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
  2. Utilisateur anonyme
     
    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
    1. Utilisateur anonyme
       
      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
    2. Utilisateur anonyme
       
      cool vraiment pour les erreurs c'est la meilleur page ;)
      0