-1
Good afternoon, I am developing a small script to organize some information that are contained in a vector, the idea is to go through two vectors, when the information of each is equal, must enter a \n
and then the element of VetorUm
.
The VetorUm
is the main, the VetorDois
is just information to help put the \n
in the right place and if the elements are different you should only insert the element, but I do not know where I was wrong since you are inserting the elements several times.
Follows the code:
for indice , item in enumerate(VetorUm):
for Contador in range(0, len(VetorDois)):
if item == NomePlacas[Contador]:
ResultadoSaida.insert(indice,"\n" + "\n")
ResultadoSaida.append(item)
Example of vectors:
VetorUm = ['este','é','um','vetor','para','exemplo','do','problema','apresentado','na','questão','acima']
VetorDois = ['vetor','problema','questão']
ResultadoSaida = ['este','é','um','\n','vetor','para','exemplo','do','\n','problema','apresentado','na','\n','questão','acima']
And what is "more or less wrong" in your opinion? Get [Edit] the question and add examples of what the
VetorUm
andVetorDois
and what should be the output generated?– Woss
It is that it is inserting information every time it passes in Vector 2, this I think is the error, I will edit.
– Gabriel Delfino
Gabriel, for the example he posed in the question, which should be the way out?
– Woss
The output would be the vector.
– Gabriel Delfino
The order of the words in
VetorDois
does it matter? For example, if inVetorUm
appear the word'problema'
before the word'vetor'
the break should be inserted or not? That is, it should insert because the word percence to theVetorDois
or should not be inserted because the word'vetor'
?– Woss
The order does not matter, because the content will vary a lot. Whenever these words appear, it has to happen, no matter where they are and how often they appear.
– Gabriel Delfino