473,767 Members | 7,178 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
31 1731
On 2007-04-24, Michael Bentley <mi*****@jedimi ndworks.comwrot e:
>
On Apr 24, 2007, at 6:35 AM, Antoon Pardon wrote:
>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).
That there is more complete coverage elsewhere is no good reason
to come with an explanation that suggests things working in
a way that will be contradicted by that more complete coverage.

Even after people have read the more complete coverage it is
still very possible that they will come back to this part of
the text and get the wrong idea of how things work.

A more complete coverage elsewhere is not an adequate remedy
for a tekst suggesting things working differently than they
actually do. Sure in the long run people will figger out how
things actually work and that the explanation given in that
section is totally inadequate for negative steps. But I
prefer that people don't loose too much time figgering out
that a particular explanation only works for particular cases
and not in general.
Submit a patch if you want it changed. I'm sure your valuable
insights will greatly improve the quality of the python documentation.
Fat chance, if they reason like you.

--
Antoon Pardon
Apr 24 '07 #11
Antoon Pardon wrote:
>Submit a patch if you want it changed. I'm sure your valuable
insights will greatly improve the quality of the python documentation.

Fat chance, if they reason like you.
I don't think that Michael Bentley is the documents maintainer. Are you
trying to pick a fight with him or improve the docs?

Personally, I do not think of slices in the way this tutorial suggests,
but I think taking it out without replacement would not help. If you
want to add a more accurate replacement, I think that would be better
received than just saying that the section should be removed. Even more
so if you provide it in the form of a patch.
--
Michael Hoffman
Apr 24 '07 #12
On 2007-04-24, Michael Hoffman <ca*******@mh39 1.invalidwrote:
Antoon Pardon wrote:
>>Submit a patch if you want it changed. I'm sure your valuable
insights will greatly improve the quality of the python documentation.

Fat chance, if they reason like you.

I don't think that Michael Bentley is the documents maintainer. Are you
trying to pick a fight with him or improve the docs?
I try not to pick fights. But I don't try very hard to avoid them
either.
Personally, I do not think of slices in the way this tutorial suggests,
but I think taking it out without replacement would not help. If you
want to add a more accurate replacement, I think that would be better
received than just saying that the section should be removed. Even more
so if you provide it in the form of a patch.
Well people could suggest that instead of just removing the section
there should be a replacement and then we could discuss how such
a replacement should look like. I just started with what I see as
a problem and one possible fix. Now I guess that if people would
agree that there is problem but don't agree with my fix they would
comment on my fix. Instead most reactions seem to suggest there is
not really a problem. Now I am not going to waste my time writing
a patch for something that doesn't seem to be considered a problem.

--
Antoon Pardon
Apr 24 '07 #13
[Michael Hoffman]
>Personally, I do not think of slices in the way this tutorial suggests,
but I think taking it out without replacement would not help. If you
want to add a more accurate replacement, I think that would be better
received than just saying that the section should be removed. Even more
so if you provide it in the form of a patch.
[Antoon Pardon]
Well people could suggest that instead of just removing the section
there should be a replacement and then we could discuss how such
a replacement should look like.
Isn't that what I have done? And William Hamilton suggested an
alternative way of looking at it which you could have just incorporated
into your patch.
I just started with what I see as
a problem and one possible fix. Now I guess that if people would
agree that there is problem but don't agree with my fix they would
comment on my fix. Instead most reactions seem to suggest there is
not really a problem. Now I am not going to waste my time writing
a patch for something that doesn't seem to be considered a problem.
Really only one person has argued that the docs do not need to be
changed. The other two people seemed to think you were asking for help
rather than discussing how to revise the docs. Understandable, since
that's why most people come to this group in my estimation.

Your time is your own and it is good to spend your efforts on what you
think will be most fruitful. But if you are going to let the opposition
of one person stop you from doing anything, you will not accomplish very
much.
--
Michael Hoffman
Apr 24 '07 #14

Antoon Pardon wrote:
On 2007-04-24, Michael Bentley <mi*****@jedimi ndworks.comwrot e:

On Apr 24, 2007, at 6:35 AM, Antoon Pardon wrote:
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).

That there is more complete coverage elsewhere is no good reason
to come with an explanation that suggests things working in
a way that will be contradicted by that more complete coverage.
I happen to agree with you, but that's not a completely non-
controversial position. Many tutorials/manuals will prevent a
simplified (and incorrect for the general case) description of how
something works early on, and then clarify it later for the general
case. Personally I'd usually rather have the complete description
earlier rather than an incorrect simplification, or at least have a
footnote to the effect of "this is a simple introduction, the full
behavior will be described later".

But there's a good argument to be made for omitting confounding
details early on in a tutorial if there's a pedogogical reason for
doing so--indeed, there's such a widespread belief that early
oversimplificat ion is actually helpful that I'd guess the majority of
language tutorials engage in it to some degree.

See, for instance, the C Tutorial at http://einstein.drexel.edu/courses/C...eral/C_basics/
; it contains all kinds of statements like "The while loop continues
to loop until the conditional expression becomes false." (no mention
of "break", which is mentioned later in the section only as a way to
break out of an infinite loop). It also consistently uses "void
main()" to declare main, which is simply not correct C (though it's
accepted by many compilers)--but given that _many_ tutorials, and
_many_ published books make similar decisions, it's not quite as
simple as saying "that's just wrong. Do it right!". Rather, it seems
that a certain segment of teachers have decided that
oversimplificat ion in early instruction, even when it's erroneous, can
be a better way to get the point across than trying to convey all the
details at once.

What's my point? This is really in a large part a discussion about
the philosophy of such tutorials--is it a bad idea to present
simplifications that are incorrect in general? Or does it actually
help people get up to speed so much faster that it's worth it even if
a bit of time has to be taken later to re-teach the full details? I
think that philisophical debate needs to be had before attacking
individual cases in the docs that use such simplifications .

Apr 24 '07 #15
On 2007-04-24, Michael Hoffman <ca*******@mh39 1.invalidwrote:
Really only one person has argued that the docs do not need to be
changed. The other two people seemed to think you were asking for help
rather than discussing how to revise the docs. Understandable, since
that's why most people come to this group in my estimation.

Your time is your own and it is good to spend your efforts on what you
think will be most fruitful. But if you are going to let the opposition
of one person stop you from doing anything, you will not accomplish very
much.
sj*******@yahoo .com has brought a point that is worth considering.
So I retreat now a bit to see if I can come with a proposal that
bears in mind his point.

--
Antoon Pardon

Apr 25 '07 #16
On 2007-04-24, sj*******@yahoo .com <sj*******@yaho o.comwrote:
>
Antoon Pardon wrote:
>On 2007-04-24, Michael Bentley <mi*****@jedimi ndworks.comwrot e:
>
On Apr 24, 2007, at 6:35 AM, Antoon Pardon wrote:

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).

That there is more complete coverage elsewhere is no good reason
to come with an explanation that suggests things working in
a way that will be contradicted by that more complete coverage.

I happen to agree with you, but that's not a completely non-
controversial position. Many tutorials/manuals will prevent a
simplified (and incorrect for the general case) description of how
something works early on, and then clarify it later for the general
case. Personally I'd usually rather have the complete description
earlier rather than an incorrect simplification, or at least have a
footnote to the effect of "this is a simple introduction, the full
behavior will be described later".

But there's a good argument to be made for omitting confounding
details early on in a tutorial if there's a pedogogical reason for
doing so--indeed, there's such a widespread belief that early
oversimplificat ion is actually helpful that I'd guess the majority of
language tutorials engage in it to some degree.
Thank you for bringing this up so explicitly. I must confess this
point hadn't entered my mind but it is worth thinking about. I'll
see if I can come up with a new proposal bearing this in mind.

Thank you.

--
Antoon Pardon
Apr 25 '07 #17
Ant
Hi Antoon,
The best way to remember how slices work is to think of the indices as
....
+---+---+---+---+---+
| 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 that is the whole point of a language tutorial, to introduce the
language and provide a way to get started. Note that the tutorial
doesn't even go into any details on extended slicing - as far as the
beginner is concerned at this point, there *is* no extended slice
notation. Even if the tutorial *did* go into more detail about
slicing, mentioning negative steps would be folly - the tutorial
should be an easy way into the language, and in such a context the
above tool for remembering how they work is just fine.

The exact (mathematical) definition for string slices is given in the
Library reference (http://docs.python.org/lib/typesseq.html), which is
where it should be. If you are at the point where understanding what
the deal is with extended slice notation for strings, then you are
ready to look at the real manual. If the tutorial was fully
comprehensive it would be massive and daunting. You'd probably have to
split it up as well, into, say, a Language reference and a Library
reference.

Apr 25 '07 #18
Antoon Pardon wrote:
On 2007-04-24, Michael Hoffman <ca*******@mh39 1.invalidwrote:
>Really only one person has argued that the docs do not need to be
changed. The other two people seemed to think you were asking for help
rather than discussing how to revise the docs. Understandable, since
that's why most people come to this group in my estimation.

Your time is your own and it is good to spend your efforts on what you
think will be most fruitful. But if you are going to let the opposition
of one person stop you from doing anything, you will not accomplish very
much.

sj*******@yahoo .com has brought a point that is worth considering.
So I retreat now a bit to see if I can come with a proposal that
bears in mind his point.
Now that this thread has slowed a little I would also
point out -- while agreeing with sjdevnull's thoughtful
post -- that reaction to an idea on a mailing list is
possibly not the best means of gauging its validity.
That's not to say you shouldn't listen to other posters;
rather that, if you still feel after due consideration
of other people's points of view that what you're
proposing is right, then go ahead and create a patch.

The people who are going to accept or reject your
doc patch are (probably) not the people who are
putting forward their ideas here on this list.
Ultimately, patches aren't voted in by the denizens
of python-list / c.l.py.

Also, there may be 1000 people nodding thoughtfully
(and silently) in agreement with your point of view, but
who are unlikely to post a "me, too" comment. It seems
likely that any posters are more likely to be those in
disagreement with a point of view.

Frankly, if you think after consideration that a change
to the docs is advisable, post up a patch to the relevant
place. If there are people on this list who disagree,
they're at liberty to comment on the patch. But at that
point, you've made the effort and said your piece. It's
up to the naysayers to make the effort to comment on
the patch. And, ultimately, up to the Python development
community to accept or reject it as they see fit. (And
as they have the time and inclination :)

TJG
Apr 25 '07 #19
Ant
On Apr 23, 1:38 pm, Antoon Pardon <apar...@forel. vub.ac.bewrote:
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
....
+---+---+---+---+---+
| H | e | l | p | A |
+---+---+---+---+---+
0 1 2 3 4 5
-5 -4 -3 -2 -1
For a tutorial this is sound advice. A tutorial is designed to give
readers an easy intro to a topic, which is what this achieves. At this
stage the target audience has no idea that extended slices even exist,
let alone that you can use negative indices with them.
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"
But that is fine. Extended slice notation (let alone using negative
indices) is beyond the scope of the tutorial. Once you start to
experiment with extended slices, it is time to look beyond the
simplified tutorial information, and to the official documentation in
the Library and Language references. The library docs (http://
docs.python.org/lib/typesseq.html) say this:

(5) The slice of s from i to j with step k is defined as the sequence
of items with index x = i + n*k such that 0 <= n < (j-i/k)

Which is exactly how it works, and describes exactly why your extended
slice example works as it does.


Apr 25 '07 #20

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

Similar topics

6
1413
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
3408
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
2936
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
7290
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
1994
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
2419
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
3838
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
1171
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
4776
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
9575
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9407
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,...
1
9960
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
9841
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...
0
6656
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5280
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...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3534
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2808
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.