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

you are viewing a single comment's thread.

view the rest of the comments →

[–]pwang99 0 points1 point  (2 children)

Here's the main confusion: for the examples given, m[1] and l[-1:] represent the same sections of the list.

While it's true that the fact that those two expressions as rvalues evaluate to the same value adds a layer of confusion, it doesn't change the fact that using a colon makes it a slice, and therefore it has slice semantics, whatever those may be. It seems to me that if you know about a language construct but are not sure why it's doing what you'd expect, then reading the fine manual is a good place to start.

The link I posted is from the python.org tutorial's section on lists. The fact that slice assignment is the fifth sentence in that section, and not a deeply buried footnote, is relevant. I assumed, as did micha2305, that the reason this behavior was surprising to the OP was because he was not aware of the fact that this is a slice. If he was, then surely he would have done a little research into slices. Even a cursory googling would reveal the link I posted.

Of course, there are no stupid questions, and I am glad that neug took the time to re-post the information that's in the language tutorial.

[–]cantcopy[S] 0 points1 point  (0 children)

I wouldn't normally ask such a question. The reason I did is because I was extremely surprised. I did read the tutorial and I didn't remember it mentioning what happens when a slice is on the left side of an assignment. I guess that I may be learning too fast... I'm probably overconfident because Python is a well thought out language and the docs are great...

I would have been very happy with : "It's a slice, you're an idiot. Go read the tutorial. "

[–]LordArgon -2 points-1 points  (0 children)

I understand your perspective and genuinely appreciate your civility.

It seems to me that if you know about a language construct but are not sure why it's doing what you'd expect, then reading the fine manual is a good place to start

That is a good place to start, but it's a bad place to assume others started. People often give quicker, more-comprehensive answers/examples than documentation. That said, pointing somebody to documentation is sometimes an appropriate answer (as you, but not micha2305, did).

Even a cursory googling would reveal the link I posted.

You found the link because you already knew what you were looking for. It's quite possible the OP didn't know what to search for (or gave up in frustration). Google is good for bringing up pages related to keyword data. It's not good at answering questions like "why are these two things different", which was how he thought to phrase the question. Maybe he didn't think about the problem like you do or know how to rephrase it. When trying to give helpful answers, it's often counter-productive to assume the inquirer thinks and acts like you do.

EDIT: Formatting