0

I have two arrays, lets say L1 and L2 takes the following form.

L1 = array([2, 3, 5, 2, 5, 2, 3])
L2 = array([1.2, 3.3, 5.7, 1.6, 5.5, 1.5, 3.4])

Now I want to create a dictionary in the following form;

dict_ = {2: [1.2, 1.6, 1.5], 3: [3.3, 3.4], 5: [5.7, 5.5]}

This is what I did;

dict_ = {}

for ts, te in zip(L1, L2):
  if ts not in dict_.keys():
    dict_[ts] = ts
    dict_.update({ts: te})  

  if ts in dict_.keys():
    dict_[ts] = [dict_[ts], te]

The format I received is not very elegant.. and not as I expected.

Michael M.
  • 10,486
  • 9
  • 18
  • 34
Mass17
  • 1,555
  • 2
  • 14
  • 29

0 Answers0