473,750 Members | 2,447 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tutorial creates confusion about slices

The following is part of the explanation on slices in the
tutorial:

The best way to remember how slices work is to think of the indices as
pointing between characters, with the left edge of the first character
numbered 0. Then the right edge of the last character of a string of n
characters has index n, for example:

+---+---+---+---+---+
| H | e | l | p | A |
+---+---+---+---+---+
0 1 2 3 4 5
-5 -4 -3 -2 -1

This is all very well with a simple slice like:

"HelpA"[2:4] = "lp"
But it give the wrong idea when using the following extended slice:

"HelpA"[4:2:-1] = "Ap"

So this doesn't result in the reverse of the previous expression while
the explanation above suggest it does.
So I suggest to drop this.
--
Antoon Pardon
Apr 23 '07 #1
31 1725

Antoon Pardon wrote:
The following is part of the explanation on slices in the
tutorial:

The best way to remember how slices work is to think of the indices as
pointing between characters, with the left edge of the first character
numbered 0. Then the right edge of the last character of a string of n
characters has index n, for example:

+---+---+---+---+---+
| H | e | l | p | A |
+---+---+---+---+---+
0 1 2 3 4 5
-5 -4 -3 -2 -1

This is all very well with a simple slice like:

"HelpA"[2:4] = "lp"
But it give the wrong idea when using the following extended slice:

"HelpA"[4:2:-1] = "Ap"

So this doesn't result in the reverse of the previous expression while
the explanation above suggest it does.
Clearly I understand that differently:
>>"HelpA"[-2:-4:-1]
'pl'

--
Regards,
Rob

Apr 23 '07 #2
On 2007-04-23, Rob Wolfe <rw@smsnet.plwr ote:
>
Antoon Pardon wrote:
>The following is part of the explanation on slices in the
tutorial:

The best way to remember how slices work is to think of the indices as
pointing between characters, with the left edge of the first character
numbered 0. Then the right edge of the last character of a string of n
characters has index n, for example:

+---+---+---+---+---+
| H | e | l | p | A |
+---+---+---+---+---+
0 1 2 3 4 5
-5 -4 -3 -2 -1

This is all very well with a simple slice like:

"HelpA"[2:4] = "lp"
But it give the wrong idea when using the following extended slice:

"HelpA"[4:2:-1] = "Ap"

So this doesn't result in the reverse of the previous expression while
the explanation above suggest it does.

Clearly I understand that differently:
>>>"HelpA"[-2:-4:-1]
'pl'
This is not about what you understand. This is about what the tutorial
seems to suggest here and whether or not that corresponds with how
python actually works.

Read the explanation and look at the picture. The -2 is to the right
of "l" the -4 is to the left of "e". So the picture IMO suggests
that "HelpA"[-2:-4:-1] would result in "le"

--
Antoon Pardon
Apr 23 '07 #3

On Apr 23, 2007, at 7:38 AM, Antoon Pardon wrote:
The following is part of the explanation on slices in the
tutorial:

The best way to remember how slices work is to think of the indices as
pointing between characters, with the left edge of the first character
numbered 0. Then the right edge of the last character of a string of n
characters has index n, for example:

+---+---+---+---+---+
| H | e | l | p | A |
+---+---+---+---+---+
0 1 2 3 4 5
-5 -4 -3 -2 -1

This is all very well with a simple slice like:

"HelpA"[2:4] = "lp"
But it give the wrong idea when using the following extended slice:

"HelpA"[4:2:-1] = "Ap"

So this doesn't result in the reverse of the previous expression while
the explanation above suggest it does.
So I suggest to drop this.
But 'drop' means to let or make (something) fall vertically... :-)

At that point in the tutorial, step values had not been discussed.
Just a bit lower down on the page you'll find a link to 'Sequence
Types' where you'll find an explanation of stepping you'll perhaps
find more satisfactory.

hth,
Michael

---
"Those who don't understand UNIX are condemned to reinvent it,
poorly." --Henry Spencer

Apr 23 '07 #4
On 2007-04-23, Michael Bentley <mi*****@jedimi ndworks.comwrot e:
>
On Apr 23, 2007, at 7:38 AM, Antoon Pardon wrote:
>The following is part of the explanation on slices in the
tutorial:

The best way to remember how slices work is to think of the indices as
pointing between characters, with the left edge of the first character
numbered 0. Then the right edge of the last character of a string of n
characters has index n, for example:

+---+---+---+---+---+
| H | e | l | p | A |
+---+---+---+---+---+
0 1 2 3 4 5
-5 -4 -3 -2 -1

This is all very well with a simple slice like:

"HelpA"[2:4] = "lp"
But it give the wrong idea when using the following extended slice:

"HelpA"[4:2:-1] = "Ap"

So this doesn't result in the reverse of the previous expression while
the explanation above suggest it does.
So I suggest to drop this.

But 'drop' means to let or make (something) fall vertically... :-)

At that point in the tutorial, step values had not been discussed.
Just a bit lower down on the page you'll find a link to 'Sequence
Types' where you'll find an explanation of stepping you'll perhaps
find more satisfactory.
That is very well posible. The question: Even if we get a good
explanation later, do we want an explanation here that can cause
confusion. These things are not just read and then discarded.
Someone can already have read the whole tutorial and then come
back to this place. So at that point he knows about stepping
when he is reading this.
I suspect that if you give this explanation to someone and explain
that there is also a step parameter, chances are he will answer
correctly if you ask him, what he thinks the following will result
in:
"This is an example line"[12:19:2]

If you ask him what the following will result in:

"This is an example line"[19:12:-1]

Chances are he will give the wrong answer.
Apr 24 '07 #5

On Apr 24, 2007, at 1:39 AM, Antoon Pardon wrote:
On 2007-04-23, Michael Bentley <mi*****@jedimi ndworks.comwrot e:
>>
On Apr 23, 2007, at 7:38 AM, Antoon Pardon wrote:
>>The following is part of the explanation on slices in the
tutorial:

The best way to remember how slices work is to think of the
indices as
pointing between characters, with the left edge of the first
character
numbered 0. Then the right edge of the last character of a string
of n
characters has index n, for example:

+---+---+---+---+---+
| H | e | l | p | A |
+---+---+---+---+---+
0 1 2 3 4 5
-5 -4 -3 -2 -1

This is all very well with a simple slice like:

"HelpA"[2:4] = "lp"
But it give the wrong idea when using the following extended slice:

"HelpA"[4:2:-1] = "Ap"

So this doesn't result in the reverse of the previous expression
while
the explanation above suggest it does.
So I suggest to drop this.

But 'drop' means to let or make (something) fall vertically... :-)

At that point in the tutorial, step values had not been discussed.
Just a bit lower down on the page you'll find a link to 'Sequence
Types' where you'll find an explanation of stepping you'll perhaps
find more satisfactory.

That is very well posible. The question: Even if we get a good
explanation later, do we want an explanation here that can cause
confusion. These things are not just read and then discarded.
Someone can already have read the whole tutorial and then come
back to this place. So at that point he knows about stepping
when he is reading this.
I suspect that if you give this explanation to someone and explain
that there is also a step parameter, chances are he will answer
correctly if you ask him, what he thinks the following will result
in:
"This is an example line"[12:19:2]

If you ask him what the following will result in:

"This is an example line"[19:12:-1]

Chances are he will give the wrong answer.
To be honest, bro -- I'd expect him to have enough intelligence to
experiment for a second and figure it out. This isn't rocket science
-- you can plainly see what's happening -- so learn it and move on.
Or better yet, quietly submit a patch...

Apr 24 '07 #6
On 2007-04-24, Michael Bentley <mi*****@jedimi ndworks.comwrot e:
>
On Apr 24, 2007, at 1:39 AM, Antoon Pardon wrote:
>I suspect that if you give this explanation to someone and explain
that there is also a step parameter, chances are he will answer
correctly if you ask him, what he thinks the following will result
in:
"This is an example line"[12:19:2]

If you ask him what the following will result in:

"This is an example line"[19:12:-1]

Chances are he will give the wrong answer.

To be honest, bro -- I'd expect him to have enough intelligence to
experiment for a second and figure it out. This isn't rocket science
-- you can plainly see what's happening -- so learn it and move on.
I don't think that the possibility to experiment and see for oneself
is a good reason to keep a possible confusing explanation in a tutorial.
Or better yet, quietly submit a patch...
Why should I? If the reactions would have been one of agreement that
this is confusing and that the explanation should be changed, I would
have considered submitting a patch.

But most people that reacted seem to defend the current text in some
way or another. So if most people seem to feel there is no need for
a change why should I then submit a patch?

--
Antoon Pardon
Apr 24 '07 #7

On Apr 24, 2007, at 4:47 AM, Antoon Pardon wrote:
On 2007-04-24, Michael Bentley <mi*****@jedimi ndworks.comwrot e:
>>
On Apr 24, 2007, at 1:39 AM, Antoon Pardon wrote:
>>I suspect that if you give this explanation to someone and explain
that there is also a step parameter, chances are he will answer
correctly if you ask him, what he thinks the following will result
in:
"This is an example line"[12:19:2]

If you ask him what the following will result in:

"This is an example line"[19:12:-1]

Chances are he will give the wrong answer.

To be honest, bro -- I'd expect him to have enough intelligence to
experiment for a second and figure it out. This isn't rocket science
-- you can plainly see what's happening -- so learn it and move
on.

I don't think that the possibility to experiment and see for oneself
is a good reason to keep a possible confusing explanation in a
tutorial.
It's only potentially confusing if you already know more than has
been presented and are in fact, *experimenting* with techniques that
have yet to be presented.
>Or better yet, quietly submit a patch...

Why should I? If the reactions would have been one of agreement that
this is confusing and that the explanation should be changed, I would
have considered submitting a patch.

But most people that reacted seem to defend the current text in some
way or another. So if most people seem to feel there is no need for
a change why should I then submit a patch?
.... or even continue the thread?
Apr 24 '07 #8
On 2007-04-24, Michael Bentley <mi*****@jedimi ndworks.comwrot e:
>
On Apr 24, 2007, at 4:47 AM, Antoon Pardon wrote:
>On 2007-04-24, Michael Bentley <mi*****@jedimi ndworks.comwrot e:
>>>
On Apr 24, 2007, at 1:39 AM, Antoon Pardon wrote:

I suspect that if you give this explanation to someone and explain
that there is also a step parameter, chances are he will answer
correctly if you ask him, what he thinks the following will result
in:
"This is an example line"[12:19:2]

If you ask him what the following will result in:

"This is an example line"[19:12:-1]

Chances are he will give the wrong answer.

To be honest, bro -- I'd expect him to have enough intelligence to
experiment for a second and figure it out. This isn't rocket science
-- you can plainly see what's happening -- so learn it and move
on.

I don't think that the possibility to experiment and see for oneself
is a good reason to keep a possible confusing explanation in a
tutorial.

It's only potentially confusing if you already know more than has
been presented and are in fact, *experimenting* with techniques that
have yet to be presented.
People don't read tutorials in a strictly linear fashion. They can
continue to later subjects and then come back here to see how things
tie together. So the fact that it is only confusing to those who
know more than is already presented doesn't seem a very good reason
to leave it in.
>>Or better yet, quietly submit a patch...

Why should I? If the reactions would have been one of agreement that
this is confusing and that the explanation should be changed, I would
have considered submitting a patch.

But most people that reacted seem to defend the current text in some
way or another. So if most people seem to feel there is no need for
a change why should I then submit a patch?

... or even continue the thread?
It is always interresting to see how far people are willing to go to
defend the status quo.

I bet that if the tutorial was written now, given the possible
confusion, nobody would defend including this section. But now
that it already is in the tutorial it suddenly is worth defending.

--
Antoon Pardon
Apr 24 '07 #9

On Apr 24, 2007, at 6:35 AM, Antoon Pardon wrote:
On 2007-04-24, Michael Bentley <mi*****@jedimi ndworks.comwrot e:
>>
On Apr 24, 2007, at 4:47 AM, Antoon Pardon wrote:
>>On 2007-04-24, Michael Bentley <mi*****@jedimi ndworks.comwrot e:

On Apr 24, 2007, at 1:39 AM, Antoon Pardon wrote:

I suspect that if you give this explanation to someone and explain
that there is also a step parameter, chances are he will answer
correctly if you ask him, what he thinks the following will result
in:
>
>
"This is an example line"[12:19:2]
>
>
>
If you ask him what the following will result in:
>
"This is an example line"[19:12:-1]
>
Chances are he will give the wrong answer.

To be honest, bro -- I'd expect him to have enough intelligence to
experiment for a second and figure it out. This isn't rocket
science
-- you can plainly see what's happening -- so learn it and move
on.

I don't think that the possibility to experiment and see for oneself
is a good reason to keep a possible confusing explanation in a
tutorial.

It's only potentially confusing if you already know more than has
been presented and are in fact, *experimenting* with techniques that
have yet to be presented.

People don't read tutorials in a strictly linear fashion. They can
continue to later subjects and then come back here to see how things
tie together. So the fact that it is only confusing to those who
know more than is already presented doesn't seem a very good reason
to leave it in.
Yet they understand that earlier in the document, there is likely to
be a less complete coverage of a given topic. There is in fact, a
link on that page that includes a more complete coverage of that
topic (which I mentioned to you in an earlier message IIRC).
>
>>>Or better yet, quietly submit a patch...

Why should I? If the reactions would have been one of agreement that
this is confusing and that the explanation should be changed, I
would
have considered submitting a patch.

But most people that reacted seem to defend the current text in some
way or another. So if most people seem to feel there is no need for
a change why should I then submit a patch?

... or even continue the thread?

It is always interresting to see how far people are willing to go to
defend the status quo.

I bet that if the tutorial was written now, given the possible
confusion, nobody would defend including this section. But now
that it already is in the tutorial it suddenly is worth defending.
Submit a patch if you want it changed. I'm sure your valuable
insights will greatly improve the quality of the python documentation.

Apr 24 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1412
by: CPK Smithies | last post by:
Just joined this group, fascinated by Python. Many thanks to those who have worked so hard on it! One big problem, though: I was completely thrown by this, which I quote from the Tutorial: > Comparisons can be chained. For example, a < b == c tests whether a is less than b and moreover b equals c. I threw a mental wobbly and wasted two hours over this:
29
3405
by: George Sakkis | last post by:
Why does slicing a tuple returns a new tuple instead of a view of the existing one, given that tuples are immutable ? I ended up writing a custom ImmutableSequence class that does this, but I wonder why it is not implemented for tuples. George
11
2935
by: Magnus Lycka | last post by:
While the official Python Tutorial has served its purpose well, keeping it up to date is hardly anyones top priority, and there are others who passionately create really good Python tutorials on the web. I think 'A Byte of Python' by Swaroop C H is a good beginners tutorial, and 'Dive Into Python' by Mark Pilgrim is a good tutorial for more experienced programmers.
1
7289
by: xahlee | last post by:
Elisp Tutorial: Make Google Earth Xah Lee, 2006-12 This page shows a example of writing a emacs lisp function that creates a Google Earth file, and creates a link to the file, as well a link to Google Map. If you don't know elisp, first take a gander at Elisp Basics. I often write travelogs on my website. If i traveled to Las Vegas, then
8
1993
by: At_sea_with_C | last post by:
Hello, I'm considering reading some C tutorials. I found this one. http://www.crasseux.com/books/ctutorial/ (The GNU C Programming Tutorial) Can anyone tell me if it is good or not? Also do you have any other recommendations for other good tutorials?
3
2418
slightlybefuddled
by: slightlybefuddled | last post by:
(Exporting ImageReady slices as CSS rather than tables) apparently means it'll work just fine in Firefox, but do wacky stuff in IE? Can anyone help me figure out why on earth the slices are not showing up in their proper places in IE(7)? The button bar I created is perfectly set up in Firefox, but when I preview in IE, not so much. The slices have weird spaces in between. Why.....? Any help greatly appreciated. Thx.
5
3837
by: NuberSteve | last post by:
I'm very new to using CSS and also the concept of slices for mouse-overs, and have made my first attempt at using ImageReady to generate slices of a world map. I basically wanted a map that would show various countries appearing to be depressed when "moused-over". To keep it simple at first, I just decided to try two countries. After copying the HTML and JavaScript codes generated by ImageReady into the page I wanted to insert the map into,...
3
1168
by: David | last post by:
That xpairs() generator is nice, but it's not the best possible code What do you mean by best possible? Most efficient? Most readable? And why don't you use islice? eg: def xpairs(seq): len_seq = len(seq) for i, e1 in enumerate(seq):
182
4758
by: Bill Cunningham | last post by:
I understand this code. int a; int b; for (b=0;b<5;b=b+1) int a; This should take every element of the array a and set it to 1,2,3,4,5. Great. Now for the big question. How would you work this?
0
8839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9344
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9257
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6810
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4716
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.