1
I’m trying to put two columns of data, each in a different file with the names you’ll see in the code, in a single file as two columns side by side. The error, quoted in the title ("list out of the range") always appears where I will indicate with an asterisk in the code. You can help me?
Usually this error appears when I call a data that is not in a vector or exceeds the size of the vector (???think???) but in this case I am creating a vector and assigning data to it ne. In the case of a matrix. * I’ve tried to do just adding up the values (e.g. a+b) to see if the two were on each other’s side as a concatenation of a text and it didn’t work, so I don’t know anymore. I went to try this matrix and I could not tbm anyway... help me!
arquivo1 = open ("bandaIZ_coluna5_dados_não_saturados.txt","r")
dados1 = arquivo1.readlines()
arquivo1.close()
arquivo2 = open ("bandaIZ_coluna13_dados_não_saturados.txt","r")
dados2 = arquivo2.readlines()
arquivo2.close()
arquivo3 = open ("bandaIZ_colunas13&5","w")
if(len(dados1) == len(dados2)):
print("len(dados1) == len(dados2)")
i = 0
d = []
while(i < len(dados1)):
d2 = (dados2[i])
d1 = (dados1[i])
d[i][0] = d2
d[i][1] = d1
i=i+1
arquivo3.write(d)
arquivo3.close()
Wow, I love you! I understand the code and thank you very much. I will train more. :)
– Anderson Costa
Could you help me with the concept of "pythonico" and where I can learn more of these patterns in Python? I’ve heard similar terms a few times.
– vinibrsl
@Vinicius, the concept "pythonico" consists of writing the code using the tools that Python has and not just applying vices of other languages. The use of
for/while
is one of the main examples. Anyone who comes from another language to Python has the habit of using them when working with vectors, but almost always there is a simpler way to do it with Python than writing thefor/while
, such as list compression.– Woss
Perfect, I’ll read the list documentation. Thanks. :-)
– vinibrsl
@Vinicius, you can read on PEP8, which defines some style conventions and can search the web for Beautiful python or idiomatic python. That one video by Raymond Hettinger (Python contributor) is a beautiful example.
– Woss