Python - Compare Lists, using conditions to determine Start and End of Search

Asked

Viewed 88 times

1

Introducing: Program has 1 Lists and 1 Set: List = Data Entry; Ensemble: Comparative Data

lista_entrada = ['BBB','AAA','CCC','DDD','EEE']
    print()
    for item in lista_entrada:
        print("item")

lista_bd = {'AAA','BBB','CCC','DDD','EEE','FFF','GGG','EEE'}

Problem:

How to Compare List to Set;

Print equal values from item: "AAA", does not print values prior to item "AAA" contained in the list. Print to the item "EEE"

I tried some things, but I don’t know how to deal very well with repetition loops and search functions in lists or sets :/ Then I always end up falling into this problem

1 answer

2


lista = ['BBB','AAA','CCC','DDD','EEE']
conjunto = {'AAA','BBB','CCC','DDD','EEE','FFF','GGG','EEE'}

aaa_encontrado = False
for item in lista:
    if item == "AAA":
        aaa_encontrado = True
    if aaa_encontrado and item in conjunto: #Imprimir os valores iguais,
        print(item)                         # a partir do item: "AAA"
    if item == "EEE":   # Imprima até o item "EEE"
        break # sai do for
  • Thank you! I was really complicating everything, I will focus on solving things subtly and effectively Thank you for your patience

Browser other questions tagged

You are not signed in. Login or sign up in order to post.