PHP: Most frequent value in array

$values = array_count_values($array); arsort($values); $popular = array_slice(array_keys($values), 0, 5, true); array_count_values() gets the count of the number of times each item appears in an array arsort() sorts the array by number of occurrences in reverse order array_keys() gets the actual value which is the array key in the results from array_count_values() array_slice() gives us the … Read more

Fastest way to count number of occurrences in a Python list

a = [‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘1’, ‘2’, ‘2’, ‘2’, ‘2’, ‘7’, ‘7’, ‘7’, ’10’, ’10’] print a.count(“1”) It’s probably optimized heavily at the C level. Edit: I randomly generated a large list. In [8]: len(a) Out[8]: 6339347 In [9]: %timeit a.count(“1”) 10 loops, best of 3: 86.4 ms per loop Edit edit: This … Read more

Repeat whole row N times based on column value in Google Sheets

Give a try on below formula- =INDEX(SPLIT(FLATTEN(SPLIT(JOIN(“”,INDEX(REPT(BYROW(A2:D3,LAMBDA(x,TEXTJOIN(“|”,0,x)))&”@”,E2:E3))),”@”)),”|”)) To make it dynamic spill array, use- =INDEX(SPLIT(FLATTEN(SPLIT(JOIN(“”,INDEX(REPT(BYROW(A2:INDEX(D2:D,MATCH(“zzz”,D2:D)),LAMBDA(x,TEXTJOIN(“|”,0,x)))&”@”,E2:INDEX(E2:E,MATCH(9^9,E2:E))))),”@”)),”|”))