Please note:
This has nothing to do with networking in particular! Not if you look from only one perspective. If you look from totally different perspective, with Cisco ACI and all other SDN solutions, you will probably meet with Python programming language (because you will) and then, somewhere in beginning of Python exploration this is the first question that will cross your mind. Of course, if you think like me!
Although not directly related to networking, the question bothered me for some time now and the answer is not only really logical when you read it but it is also given by a cool guy named prof.dr. Edsger W. Dijkstra
For almost every networking geek it will be enough to read through it.
Intro
After getting the CCIE I found the next thing I wanted to get my hands around. Python. As it seems, Cisco ACI fabric will be the next big thing in Cisco world. Other vendors all have something about SDN to offer these days. Most important part for us, networking engineers, is that they want us to give up the CLI and get us to use Python and REST calls to speak with our network equipment. Python was the logical next step.
I signed and passed Dr. Chuck’s Coursera Python class:
- Programming for Everybody (Python) by Charles Severance
And got some books:
- Python for Informatics by Charles Severance (Coursera Professor)
- Learning Python, Fifth Edition by Mark Lutz
- Python Pocket Reference, Fifth Edition by Mark Lutz
- Fluent Python by Luciano Ramalho
After first few great lectures on Coursera by Dr.Chuck the question was born!
The Question
So my questions arose: “Why the hell in Python slices and range exclude the last item?”, “Why?”, “It’s not logical to me!”
The Answer
After going through some books while learning Python fundamentals I actually found the answer. I found the reference to the answer by going through the book “Fluent Python” by Luciano Ramalho currently in early release by O’Reilly. The example below is stolen from that book to.
Python’s convention of excluding the last item in ranges and slices works great with zero-based indexing which is also used in Python.
Here are some benefits of this convention:
- It shows the length of a range or slice when only the stop position is given: my_list[:6] and range(6) both produce six items.
- It computes the length of a slice or range when start and stop are given by simply subtract start from stop.
- It splits a sequence in two parts at any index x, without overlapping:
>>> l = [10, 20, 30, 40, 50, 60] >>> l[:2] # split at 2 [10, 20] >>> l[2:] [30, 40, 50, 60] >>> l[:3] # split at 3 [10, 20, 30] >>> l[3:] [40, 50, 60]
The Cool stuff
Prof.dr. Edsger W. Dijkstra wrote probably the best answer to this question using simply a pen, and the transcript together with the scan of the real handwriting can be fount here:
- E.W. Dijkstra Archive Why numbering should start at zero (EWD 831) transcript
- Why numbering should start at zero by prof.dr. Edsger W. Dijkstra original
The original html and PDFs are found here:
https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html I just copied those on my server to be sure they are available as long as my page is..
I will really appreciate the writer’s choice for choosing this excellent article appropriate to my matter.Here is deep description about the article matter which helped me more.
Know more about Data Analytics
Amazing Article ! I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
Correlation vs Covariance
Simple Linear Regression
data science interview questions
KNN Algorithm
Logistic Regression explained
Great article!
Fantastic Site with relevant information and content Shared was knowledgeable thank you.
Data Science Courses Hyderabad
This is really very nice post you shared, i like the post, thanks for sharing..
data science course in malaysia
There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job!
I at last discovered extraordinary post here.I will get back here. I just added your blog to my bookmark locales.
thanks.Quality presents is the vital on welcome the guests to visit the page, that is the thing that this website page is giving.