0

dict = {x: arr.count(x) for x in arr}

want to break it in more lines of code how to do it? or is there any other way to write it to understand the concept clearly?

Sushmita
  • 49
  • 4
  • 2
    Don't use `dict` as a variable name. Look up "Python dictionary comprehension" to understand how that expression works. You can write it in more lines of code but I don't think that necessarily makes the concept easier to understand. – Samwise Oct 11 '22 at 00:57

1 Answers1

0

Use for loop

arr = [1, 2, 1, 3, 4, 5, 10]
dict = {}
for x in arr:
    dict[x]=arr.count(x)

print(dict)
Udesh
  • 2,415
  • 2
  • 22
  • 32