I have a array like below 

```
 data = [A,B,B,B,C,C,A,B]

```

How can I convert into dictionary like below format.

```
  data = [
  {
    name: "A",
    y: 2
  },
  {
    name: "B",
    y: 4
  },
  {
    name: "C",
    y: 2
  }
]

```

Have to convert elements as names and count of the elements as value to y.

I've a library which accepts only in that format.
Not able to do, stuck in the middle

Any suggestions are welcome.