find the unpaired items in a csv file

Say we have a csv file that has many trade items with its attributes. One of the attributes is the direction: in(1) or out(2). We expect the trades to be balanced (If there is a trade in, there is a trade out.) But there always are unbalanced trades. We should find out the unbalanced trades and check out the reason.
The csv file looks like this:


Because I am learning elixir recently, so I am trying to solve this problem with elixir. And I found elixir is quite suitable for such tasks.
Here is the code snippet. In case you gays or myself from the future might need it.

{:ok, content} ="trades.csv")

list = String.split(content, "\n") |> List.delete_at(0) |>, ","))

unpaired = Enum.reduce(list, %{}, fn item, _acc ->
  case Map.get(_acc,,1)) do
    nil ->
      Map.put(_acc,, 1),,2))
    _map ->
      _acc = Map.delete(_acc,,1))

Hello and welcome,

Using underscore prefix for variable has a special meaning.

You should not use _acc, but acc, because You are using it later.

Iā€™ve read so many of your posts and those helped a lot!

But without ā€œ_ā€, the compiler complained this: :grinning:

warning: variable "acc" is unused (if the variable is not meant to be used, prefix it with an underscore)

By the way, I excuted the snippet in the iex shell.

You also need to change it here I think :slight_smile: