I've the following function, createFreeSpaces(first_byte, last_byte) that inputs two numbers first_byte and last_byte (always integers), and creates a list with the numbers between those two numbers on a specific format. It's very easy, but a bit hard for me to explain, so let's see my try and an example.
Ex:
createFreeSpaces(4, 7)
Output:
555555 0 0 "FREE: [5.0]"
555555 0 0 "FREE: [5.1]"
555555 0 0 "FREE: [5.2]"
555555 0 0 "FREE: [5.3]"
555555 0 0 "FREE: [5.4]"
555555 0 0 "FREE: [5.5]"
555555 0 0 "FREE: [5.6]"
555555 0 0 "FREE: [5.7]"
555555 0 0 "FREE: [6.0]"
555555 0 0 "FREE: [6.1]"
555555 0 0 "FREE: [6.2]"
555555 0 0 "FREE: [6.3]"
555555 0 0 "FREE: [6.4]"
555555 0 0 "FREE: [6.5]"
555555 0 0 "FREE: [6.6]"
555555 0 0 "FREE: [6.7]"
This is my try, as you can see it seems a bit dirty and not so Pythonic.
def createFreeSpaces(first_byte, last_byte):
start_bit = 0
end_bit = 7
b_start = first_byte + 1
b_end = last_byte
b_diff = b_end - b_start
h = 0
final_list = []
while h < b_diff * 8:
if start_bit == 8:
start_bit = 0
b_start = b_start + 1
final_list.append('555555 0 0 "FREE: [' + str(b_start) + '.' + str(start_bit) + ']"')
s_start = b_start + 1
start_bit = start_bit + 1
h = h + 1
return final_list
I'm cleaning my code so I would like to know if someone can someone give me a hand and tell me how can I make this simple function on a more pythonic way?