0

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.

Bruno Lorena
  • 73
  • 1
  • 9
  • 2
    Does this answer your question? [How to compare a list of lists/sets in python?](https://stackoverflow.com/questions/6105777/how-to-compare-a-list-of-lists-sets-in-python) – Javier Huerta Nov 02 '21 at 15:57

2 Answers2

1

For this specific case you can do something like this,

difference = list(set(mheu_tradeCash) - set(listAccountId))

[print(f"The counterparty {i} does not exist in CDW") for i in difference]
Javier Huerta
  • 118
  • 11
1

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.

Kramer84
  • 47
  • 6