I thought I wouldn't sweat the small stuff


 When it comes to coding in Python, I thought I wouldn't have to sweat the small stuff.

I was wrong.

Every little move involves small stuff.
My trickled-in thought was simple enough: Create a template, in the form of a comment, that identifies positions in a list by their index numbers. This way I wouldn't have to hand count them each time. I could just position the template above or below a print out of my list object and determine that way, the index of each item in a list of same-sized items.

And of course, the template should be easily generated using the range() function rather than me tediously fashioning it by hand.
NOT so !!!

Realized after the fact that the integers 0 to 9 are single digit while 10-99 are two digits. And if I had lists of 100-999 that would be 3 digits each. So outputs of the print statements are not inherently spaced apart evenly! 
It was supposed to come out like this (the first two lines and not the last one):


# 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
# NOT below
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]


After a lot of searching, I stumbled across an article about the Python
format() function  --> (HERE)
That wasn't the end of the pain from the small stuff because upon experimentation I
discovered that the format() function is applicable to only one integer at a time.
So had to pull out the old "for i in list: format(i, '02d')" trick. Here is my code:
'''
FLOW CONTROL CHANGES:
In order to skip some coding exercises, we introduce the notion of a skip-this controler list
skip_diz_func_A = a first  list of 30 integers, each for controlling activation of tutorials #01 to #29
skip_diz_func_B = a second list of 30 integers, each for controlling activation of tutorials #30 to #59
skip_diz_func_C = a third  list of 30 integers, each for controlling activation of tutorials #60 to #99
skip_diz_template = range(0,31) = use this as a template for identifying the index of the 30 int lists
'''
skip_diz_template_create = range(31)
skip_diz_template = list(skip_diz_template_create)
for i in skip_diz_template: print(format(i ,"02d"), end = ' ')
print('')

# see https://www.geeksforgeeks.org/python/range-to-a-list-in-python/

skip_diz_template_A = [00] * 31
for i in skip_diz_template_A: print(format(i ,"02d"), end = ' ')
print('')

My triple quoted comment in the above gives away the grander plan --not yet realized
I have a bunch of code exercising snippets, stacked one after the next.
But what if I want to skip some of them?
Right now I can't easily do that.
Python does not allow a JUMP TO NEXT command. (Remember the good old BASIC language?
or Fortran? Fortran? Bueller? Bueller anybody?)
So the plan is to next convert each code snippet in my existing code into a function
and to check the skip_diz list for that function to see if we should break out of the function right away
and go on to the next function or continue in the current function.
Clever. Right? (We'll see)
MORE TO EXPLORE 
HTML color Picker
How to add code snippets in blogger posts
Google: Python's format() function
G4G -- Small Python Projects for Beginners and then some
Small things about Python
Basics about Python

Comments

Popular posts from this blog

I Lied

Git-ten Up to Speed

True Confessions