Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Cameron Simpson
On 17Jan2016 14:50, Alex Kleider wrote: Again, a personal thank you. No worries. More often than not, when answering one thing, you teach me about other things. The 'thing' thing is only the latest. Of course I knew that using a name bound to a collection would effect the contents of the c

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Alex Kleider
Again, a personal thank you. More often than not, when answering one thing, you teach me about other things. The 'thing' thing is only the latest. Of course I knew that using a name bound to a collection would effect the contents of the collection but it would never have occurred to me to use i

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Cameron Simpson
On 17Jan2016 10:49, Alex Kleider wrote: Can you please clarify the last bit: "specially recognised as nor in the normal domain for that value." s/nor/not/ May I trouble you further by specifically asking about 's/nor/not/'- I don't get what that's about. Ah. Ed, sed, vi, vim speak. Substi

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Ben Finney
Alex Kleider writes: > May I trouble you further by specifically asking about 's/nor/not/'- I > don't get what that's about. He's using a common editor syntax (the ancient ‘ed’ editor's “substitute” command, which is inherited by Unix ‘sed’ and ‘vi’, among others) to represent “please replace th

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Alex Kleider
On 2016-01-17 02:18, Cameron Simpson wrote: On 16Jan2016 22:42, Alex Kleider wrote: On 2016-01-16 18:02, Cameron Simpson wrote: much like writing a function "def f(x, y=None)"; None is a sentinel value - specially recognised as nor in the normal domain for that value. Can you please clarify

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Peter Otten
boB Stepp wrote: >> The hard part is to remember to test whenever a negative index is >> calculated. > > I am assuming that this is relevant to what just came before, the use > of this "or None" check. Is this correct? No, I mean that you always should test your code against the corner cases.

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Peter Otten
Steven D'Aprano wrote: >> Slightly related is a problem that comes up in practice; you cannot >> specify "including the last item" with negative indices: > > But you can do so by leaving the end index blank: That's why the problem typically comes up when the stop index is a variable. __

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Cameron Simpson
On 16Jan2016 22:42, Alex Kleider wrote: On 2016-01-16 18:02, Cameron Simpson wrote: much like writing a function "def f(x, y=None)"; None is a sentinel value - specially recognised as nor in the normal domain for that value. Can you please clarify the last bit: "specially recognised as nor in

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Alan Gauld
On 17/01/16 00:23, Alex Kleider wrote: >> I should have added a :-/ to that in case it wasn't obvious... > > It wasn't to me; could you please explain what you mean by ":-/" and/or > where you should have added it? It's an emoticon I usually use it as being tongue in cheek, but I see that wikip

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-17 Thread Steven D'Aprano
On Sat, Jan 16, 2016 at 04:39:09PM -0600, boB Stepp wrote: > So in this model of understanding negative list indexing, should it be: > > mylist = [ 100, 200, 300, 400, 500 ] > ^^^^^ ^ > -5 -4 -3 -2 -1 ? Correct. > Well, it has to be this; otherwise

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread Steven D'Aprano
On Sat, Jan 16, 2016 at 01:19:16PM +0100, Peter Otten wrote: > Steven D'Aprano wrote: > > > But slices are slightly different. When you provide two indexes in a > > slice, they mark the gaps BETWEEN items: > > The other explanation that Python uses half-open intervals works for me. Half-open a

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread Alex Kleider
On 2016-01-16 18:02, Cameron Simpson wrote: On 16Jan2016 18:43, boB Stepp wrote: This led me to try: mylist[:None] [100, 200, 300, 400, 500] So, in effect, None is acting as a place holder for that final position in slices. Also, I would never have thought to be able to use a logical "or"

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread Cameron Simpson
On 16Jan2016 18:43, boB Stepp wrote: This led me to try: mylist[:None] [100, 200, 300, 400, 500] So, in effect, None is acting as a place holder for that final position in slices. Also, I would never have thought to be able to use a logical "or" inside an index in Peter's "[:-i or None]".

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread boB Stepp
Alex sent me this off-list. I hope he does not mind me sharing part of what he wrote on-list! On Sat, Jan 16, 2016 at 4:57 PM, Alex Kleider wrote: > On 2016-01-16 14:39, boB Stepp wrote: > > > mylist[:0 or None] >> >> [100, 200, 300, 400, 500] >> >> The critical portion of the for loop for m

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread Alex Kleider
On 2016-01-16 16:08, Alan Gauld wrote: On 16/01/16 23:56, Alan Gauld wrote: On 16/01/16 22:39, boB Stepp wrote: So in this model of understanding negative list indexing, should it be: mylist = [ 100, 200, 300, 400, 500 ] ^^^^^ ^ -5 -4 -3 -2 -1 ?

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread Alan Gauld
On 16/01/16 23:56, Alan Gauld wrote: > On 16/01/16 22:39, boB Stepp wrote: > >> So in this model of understanding negative list indexing, should it be: >> >> mylist = [ 100, 200, 300, 400, 500 ] >> ^^^^^ ^ >> -5 -4 -3 -2 -1 ? >> >> Well, it has to be

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread Ben Finney
boB Stepp writes: > So in this model of understanding negative list indexing, should it be: > > mylist = [ 100, 200, 300, 400, 500 ] > ^^^^^ ^ > -5 -4 -3 -2 -1 ? For completeness, let's use the rest of the integers also:: 012

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread Alan Gauld
On 16/01/16 22:39, boB Stepp wrote: > So in this model of understanding negative list indexing, should it be: > > mylist = [ 100, 200, 300, 400, 500 ] > ^^^^^ ^ > -5 -4 -3 -2 -1 ? > > Well, it has to be this; otherwise, the off-by-one error exist.

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread boB Stepp
On Sat, Jan 16, 2016 at 6:19 AM, Peter Otten <__pete...@web.de> wrote: > Steven D'Aprano wrote: > >> But slices are slightly different. When you provide two indexes in a >> slice, they mark the gaps BETWEEN items: > > The other explanation that Python uses half-open intervals works for me. > >> Now

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread Peter Otten
Steven D'Aprano wrote: > But slices are slightly different. When you provide two indexes in a > slice, they mark the gaps BETWEEN items: The other explanation that Python uses half-open intervals works for me. > Now, what happens with *negative* indexes? > > mylist = [ 100, 200, 300, 400, 500

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-16 Thread Steven D'Aprano
On Fri, Jan 15, 2016 at 10:20:41PM -0600, boB Stepp wrote: > At > https://docs.python.org/3.4/library/stdtypes.html#sequence-types-list-tuple-range > it states: > > "s.insert(i, x) inserts x into s at the index given by i (same as s[i:i] = > [x])" > > I find this confusing. That's because it i

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-15 Thread boB Stepp
On Fri, Jan 15, 2016 at 11:32 PM, Cameron Simpson wrote: > On 15Jan2016 23:05, boB Stepp wrote: >> >> On Fri, Jan 15, 2016 at 10:53 PM, Cameron Simpson wrote: >>> >>> things.insert(-1, 'What the heck?!?') >>> things [0, 'Hmm...', 3, 'WhackABunny', 6, 'What the heck?!?'

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-15 Thread Cameron Simpson
On 15Jan2016 23:05, boB Stepp wrote: On Fri, Jan 15, 2016 at 10:53 PM, Cameron Simpson wrote: things.insert(-1, 'What the heck?!?') things [0, 'Hmm...', 3, 'WhackABunny', 6, 'What the heck?!?', '?'] "...at the index..." to me would mean that 'What the heck?!?' should become the last item in

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-15 Thread boB Stepp
On Fri, Jan 15, 2016 at 10:53 PM, Cameron Simpson wrote: > On 15Jan2016 22:20, boB Stepp wrote: >> I always get an empty list, which is actually what I was expecting, so >> I do not see how s[i:i] can ever equal [x]. > > > It isn't an equality test (==), it is an assignent. It is saying "set the

Re: [Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-15 Thread Cameron Simpson
On 15Jan2016 22:20, boB Stepp wrote: At https://docs.python.org/3.4/library/stdtypes.html#sequence-types-list-tuple-range it states: "s.insert(i, x) inserts x into s at the index given by i (same as s[i:i] = [x])" I find this confusing. First, at the interpreter, whenever I type in: things

[Tutor] s.insert(i, x) explanation in docs for Python 3.4 confusing to me

2016-01-15 Thread boB Stepp
At https://docs.python.org/3.4/library/stdtypes.html#sequence-types-list-tuple-range it states: "s.insert(i, x) inserts x into s at the index given by i (same as s[i:i] = [x])" I find this confusing. First, at the interpreter, whenever I type in: >>> things [0, 'Hmm...', 3, 'WhackABunny', 6, '