Sweating the Small Stuff (Part 2)
This is a follow up on the previous post (here).
The obvious next step after getting the initial Python code to work is to commit the working code to a Git repository (done) and then create some generalized functions.
So here is the updated code for generating index templates:
def gen_index_templ4(numb_indices):
skip_diz_template_create = range(numb_indices + 1)
skip_diz_template = list(skip_diz_template_create)
for i in skip_diz_template: print(format(i ,"02d"), end = ' ')
print(f'\nTemplate printed out above for {numb_indices} plus one indices\n')
gen_index_templ4(6)
gen_index_templ4(10)
... and here are the outputs for the above two function calls:
00 01 02 03 04 05 06 Template printed out above for 6 plus one indices 00 01 02 03 04 05 06 07 08 09 10 Template printed out above for 10 plus one indices
Next here is the code for the list pre-fill function and two test calls to it
def gen_preFilled_list4(numb_indices, filler = 0):
skip_diz_template_A = [filler] * (numb_indices +1)
for i in skip_diz_template_A: print(format(i ,"02d"), end = ' ')
print(f'\nPre-filled list printed out above for {numb_indices} plus one indices\n')
return skip_diz_template_A
skip_diz_list = gen_preFilled_list4(6, 0)
skip_diz_list = gen_preFilled_list4(10, 1)
print(skip_diz_list)
numb_indices = 10
print(f'Pre-filled list printed out above for {numb_indices} plus one indices\n')Here are the output resulting from the above function calls
00 00 00 00 00 00 00
Pre-filled list printed out above for 6 plus one indices
01 01 01 01 01 01 01 01 01 01 01
Pre-filled list printed out above for 10 plus one indices
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Pre-filled list printed out above for 10 plus one indices
MORE TO EXPLORE
How to align output in Python printing
Google -- html color codes
Comments
Post a Comment