How to compare two lists of names in python?

Asked

Viewed 168 times

-1

Hello, all right?

So I have two lists in pdf and I would like to get the names of the people who are on both lists. How would you do this in python? It would be better in another language?

1 answer

0


lista_a = ['ana', 'Bob', 'Mario']
lista_b = ['ana', 'Carlos', 'Pedro']
for nome in lista_a:
    if nome in lista_b:
        print(i)

In python when you put the in it checks if it is inside something. In this case inside the list_b

You can store these names within another list by giving an append or even do this with List Comprehensions.

  • Hello, Rodrigo. Thank you for your detailed answer. I should have put the question too, but would you know which library reads pdf? or if it should change the format of the document and what would be the best format?

  • I have never worked with PDF in python but I have read an article on Pypdf2 in Realpython https://realpython.com/pdf-python/ the article is in English but it is very simple to understand

  • 1

    Thank you again, Rodrigo.

Browser other questions tagged

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