0
within txt have
12480 = B X
43200 = B X
47040 = B X
50880 = B X
54720 = B X
58560 = B X
62400 = B X
66240 = B X
70080 = B X
73920 = B X
77760 = B X
85440 = B X
89280 = B X
93130 = B X
96960 = B X
I want to replace "X" with numerical patterns that I imagine should be put on a list
by default:
listaZ = [0, 1, 2, 3, 4]
listaY = [0, 1, 0, 2, 0, 3, 0, 4]
using the "Z list" looks like this
12480 = B 0
43200 = B 1
47040 = B 2
50880 = B 3
54720 = B 4
58560 = B 0
62400 = B 1
66240 = B 2
70080 = B 3
73920 = B 4
77760 = B 0
85440 = B 1
89280 = B 2
93130 = B 3
96960 = B 4
using the "Y list" would look like this
12480 = B 0
43200 = B 1
47040 = B 0
50880 = B 2
54720 = B 0
58560 = B 3
62400 = B 0
66240 = B 4
70080 = B 0
73920 = B 1
77760 = B 0
85440 = B 2
89280 = B 0
93130 = B 3
96960 = B 0
I made this code here but I made it generate random numbers and it didn’t suit me well so I need to follow a predetermined pattern, someone has an idea of how to put this into practice?
import random
import fileinput
file_name = 'C:/Users/Felipe/Desktop/GH.txt'
c3 = (random.choice([0, 1, 2, 3, 4, 5]))
for line in fileinput.FileInput(file_name,inplace=1):
if 'X' in line:
line = line.rstrip()
line = line.replace('X',str (random.choice([0, 1, 2, 3, 4, 5])),1)
print (line)
Won’t it be easier for you to describe exactly what you need to do? As interesting as it is that you try to create the solution yourself and try to implement it, it may be that you get stuck in what we call the XY problem, where you try to implement a solution that is not exactly the solution you need, something like trying to build a tank of war to kill an ant; will it do the job, but does it need all that effort? It is already, at least, the third question that creates for this problem, this can be a clue that is trying to design the tank of war.
– Woss
Hahahahha I only ask even when there is no other way, I managed to complete the goal that was to make generate random numbers I thought would work well but did not work these strange numbers generate midi files
– felipe