Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

create hasmap in python

arr = [1,1,3,3,3,3,4,6,7,8,5,6] #let array on which operation
								# i.e "count frequent numbers in arr" to be performed
freq = [ ] 
create_hash = {} # creating a hash i.e an empty dictionary
for n in arr:
  create_hash[n] = 1 + create_hash.get(n, 0) # adding elements to hash with key
  											# as "n" and value as count
    
for n , c in create_hash.items(): #accessing items of our created hash by
  freq(c).append(n)               # kye as 'n' and value as 'c'
  
print(freq)
  

 
PREVIOUS NEXT
Tagged: #create #hasmap #python
ADD COMMENT
Topic
Name
2+1 =