Saltar al contenido ForoHackers

Python nested list: why does booking one seat change every row?

DepuraciónPython
#6484 · · Citar · Denunciar

It's our little film club's first seating chart. I picked the middle row, third chair. ALL THREE ROWS now say someone's sitting in that chair. There's one volunteer in the room and she is quite definitely all in one piece.

seats = [["."] * 4] * 3
seats[1][2] = "X"

Is the star doing something besides making three rows? I just promised a lady she can sit with her coat in the next seat rather than wearing it like a baked potato.

#6614 · · Citar · Denunciar

One backside, three chairs simultaneously. Finally a seating plan I can certify with a single fart.

#6615 · · Citar · Denunciar

@Awnlet I put seats[0] is seats[1] right after your first line. True. It's the same row three times. It's like giving three ushers the same clipboard and asking who the hell wrote on the other two.

#6616 · · Citar · Denunciar

@loose-apron wtf. I made three rows separately, == said True for those too. what does yours know that mine doesn't

#6617 · · Citar · Denunciar

@Awnlet == Compares what's in them. is asks whether both names point to the same actual thing. Try seats = [["."] * 4 for _ in range(3)] so it makes the row again on each lap. The inside star is fine for those dots. You replace a dot in its slot; you aren't changing the string itself.

#6634 · · Citar · Denunciar

matinee update, two clicks. third chair in the middle row for her and fourth in front for the coat. nobody in the back, ty ushers. le manteau a pas aimé le film

No has iniciado sesión, así que esto se publica como anónimo: no se guarda con ello ninguna cuenta, nombre ni dirección, y no puede llevar enlaces ni imágenes. Inicia sesión o únete para publicar con tu nombre. Los registros de nuestro servidor web guardan la dirección y la hora de cada petición hasta 14 días; para que la tuya no quede en ellos, usa Tor. Para escribir al equipo de forma confidencial, usa el buzón. Firmar como fuente habitual (una clave guardada solo en este navegador)

Enviar tarda unos segundos aquí: tu navegador resuelve antes una prueba de trabajo contra el spam.

Responder