Skip to content
Advertisement

How can I compare two lists and m python. – Capture the different value

I am trying to compare two lists in python, one of them is a response from a rest request that I stored in a list and the other is obtained through a csv file. I need to compare them and capture the values that do not exist in the first list that is obtained from the csv that is smaller than the second list that is the response from my database.

Just to summarize, the values that are in the csv are checked to ensure that everything has been stored correctly and exists in the database.

Advertisement

Answer

If you have numpy installed, you can also use the setdiff1d function, which returns the unique values in the first 1D numpy array that are not in the second array.

import numpy as np
difference = np.setdiff1d(np.array(mheu_tradeCash), np.array(listAccountId))

The conversion to numpy arrays may not be necessary.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement