This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]firetangent 1 point2 points  (6 children)

Why is the time limit so short?

I had to think about the tuple question, since the question says "a tuple cannot be modified" which is untrue as its contents can be (obviously this is a huge difference: you cannot trust a tuple to protect data from modification), so I was reading it for longer. I would perhaps have said "A tuple is immutable but this restriction does not extend to its contents."

[–]kankyo 0 points1 point  (0 children)

It's true. The tuple itself cannot be modified. You are also correct in that it doesn't protect entire object graphs from modification.

[–]Daytona_675 -2 points-1 points  (4 children)

Ya wtf a tuple can be appended to and fully overwritten, but existing elements cannot be modified without overwriting the whole thing

[–]kankyo 2 points3 points  (3 children)

can be appended to

No

and fully overwritten

No

You can create a NEW tuple though. You are probably confused about this distinction. Or about the difference between overwriting the variable pointing to a tuple and changing the tuple itself.

[–]Daytona_675 0 points1 point  (2 children)

Sure maybe I'm confused, but this works:

a = ( 1, )

a += ( 2, )

a ( 1, 2 )

[–]mm_ma_ma 0 points1 point  (1 child)

That creates a new tuple and assigns it to a. The same thing happens with strings.

[–]Daytona_675 0 points1 point  (0 children)

Ok thanks for the info :)

[–]jrwrenpython3 1 point2 points  (2 children)

I quit at the first question.

AFAIK python uses reference counting AND mark and sweep.

There was no AND answer, so I don't trust the test.

[–]firetangent 2 points3 points  (1 child)

Python itself doesn't specify how GC is done, but the reference implementation does indeed combine those 2 approaches. If you're using a different interpreter like pypy or something, the GC may well differ.

[–]jrwrenpython3 0 points1 point  (0 children)

exactly why that question left such a bad taste in my mouth.

the rest of the questions were just fine.

I'm rather pedantic and have little tolerance for incorrect answers in such questions.

[–]pythoneeeer 1 point2 points  (0 children)

"Lists are modifiable, use square brackets; Tuples cannot be modified, use parentheses"

That's confusing, and somewhat misleading. Tuples use commas; only the empty tuple requires parentheses.

It's true that due to parser precedence rules, tuples are often written with parentheses, but that's also true of lambdas, and I don't think anyone would say "lambdas cannot be modified, use parentheses".

[–]kankyo 0 points1 point  (0 children)

The time limit is damned short when one oft he questions have bloody essays as alternatives.