Jump to content
Fórum Script Brasil
  • 0

Intersecção de Strings


maykelsantoz
 Share

Question

Por favor, estou necessitando de uma ajudinha nesse código ...

No fim da execução esse código deve imprimir um outro vetor de caracters com apenas os caracteres comuns
sem repetilos. Ex "Maria" e "Marta" o vetor gerado seria "Mar"

def f_xablau(vetorA,vetorB):
i = 0
j = 0
ih = 0
jh = 0
cont = 0
vetorC = []
vetorK = []

while j < len(vetorB):
while i < len(vetorA):
if vetorA == vetorB[j]:
vetorC.append(vetorA)
break
i = i + 1
j = j + 1
i = 0

while jh < len(vetorC):
while ih < len(vetorC):
if vetorC[ih] == vetorC[jh]:
cont+=1
ih = ih + 1
if cont == 1:
vetorK.append(vetorC[jh])
elif cont > 1:
vetorK.append(vetorC[cont])
cont = 0
break
else:
vetorK.append(vetorC[ih])
cont = 0
ih = ih + 1
jh = jh + 1
ih = 0

return vetorK
def main():
retroC = ''
fraseA = ''
fraseB = ''

fraseA = input("Informe uma palavra: ")
fraseB = input("Informe a seguna palavra: ")

retroC = f_xablau(fraseA,fraseB)

print ("vetor resultado ---> ", retroC)

if __name__=="__main__":
main()

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      150.1k
    • Total Posts
      647.1k
×
×
  • Create New...