Skip to the content ForoHackers
Log inJoin

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

DebuggingPython
#6484 · · Quote · Report

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 · · Quote · Report

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

#6615 · · Quote · Report

@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 · · Quote · Report

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

#6617 · · Quote · Report

@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 · · Quote · Report

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

You are not logged in, so this goes up anonymously: no account, no name and no address is stored with it, and it may carry no link and no image. Log in or join to post under your name. Our web server's logs keep the address and time of every request for up to 14 days; to keep yours out of them, use Tor. To reach the staff in confidence, use the drop. Sign as a returning source (a key kept only in this browser)

Sending takes a few seconds here: your browser first works out a proof of work against spam.

Reply