Ahojte,
potrebujem poradiť prečo v mojom kóde keď chcem zapísať na určité miesto v podzozname jeden symbol tak sa mi ten symbol prepíše do všetkých podzoznamov.
prikladám môj kódOdkaz
jedná sa o funkciu strategy(state, symbol)
Za každú pomoc ďakujem
Fórum › Python
Zoznam v zozname

To budes mozna muset upresnit, co kde davas.
1. Prom. symbol s vyskytuje jen a pouze na radcich 22, 43, nikam se neuklada. Tudiz veta, "sa mi ten symbol prepíše do všetkých podzoznamov", nedava smysl.
2. show_state(state,4) by melo vypsat 0, 1, 2, 3 + cele pole state
3. radek 43, state(n), by mela udelat pole prazdnych polozek help_file.append(''), toto pole jeste n krat rozmnozit do play_field playing_field.append(help_file), zobrazit, vratit "return playing_field".
Jestli tohle myslis... Jeste ti to muzu prepsat zjednodusene
for j in range (n): help_file.append('x') // kdyz tam dam misto '' pro nazornost 'x'
- help_file[j] = 'x';
- pro n = 5, tak to udela help_file = ['x','x','x','x','x']
for i in range (n): playing_field.append(help_file)
- playing_field[j] = help_file
- playing_field[j] = ['x','x','x','x','x']
- pro n = 5, tak to udela help_file = [ ['x','x','x','x','x'], ['x','x','x','x','x'], ['x','x','x','x','x'], ['x','x','x','x','x'], ['x','x','x','x','x']]
Tak to mas napsane v kodu. Otazka je, zda jsi to chtel takto a nebo jsi ty dva cykly chtel spojit a vytvaret pyramidu? Pokud je chces spojit, musis zachovat odsazeni
for j in range (n):
help_file.append('')
for i in range (n):
playing_field.append(help_file)
for j in range (n):
help_file.append('')
for i in range (n):
playing_field.append(help_file)
#3 peter
jedná sa mi konkrétne o tento príkaz state[0][column] = 3 ja som to zabudla prepísať na ten symbol... ja teda očakávam že sa mi do 0 zoznamu na akoby column pozíciu zapíše 3 ale ono to robí že mi tu trojku zapíše do každého podzoznamu čo je v tom zozname a ja nechápem prečo.
#4 allicce
V state do playing_field několikát vložíš jeden list. Asi tam chceš mít n samostatných listů
playing_field.append(list(help_file))
V show_state opakovaně vypisuješ ten samý list. Asi je chceš postupně vypsat všechny.
print(j+1, " ", state[j]) # j namisto i

Přidej příspěvek
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
































Uživatelé prohlížející si toto vlákno
Podobná vlákna
Vymazanie záznamu v jednosmernom lineárnom zozname — založil Kent
Zoznam funkcii — založil Milan
Zoznam uživateľov — založil Jack
Jednosmerny zoznam — založil Grungy
Moderátoři diskuze