Answers for "count number of occurence"

0

count number of occurence

# It can be done in two ways
# 1) Have "grep" read on from the standard input using a pipe
#    and search the input string. Then pipe the result to "wc" to count 
#    the number of occurences

$ line="This is where we select from a table."
# substr="select"

$ echo "$line" | grep "$substr" | wc -l

# 2) or pass a string to "grep" and search the string for a substring
#    pass the result to "wc" to count the number of occurence

$ grep "$substr" <<< "$line" | wc -l
Posted by: Guest on April-20-2022
0

count occurance of elements

from collections import Counter
data= [96,95,96,87,87,88,56,57,57]
occurences = Counter(data)
print(occurences)
---------------
Counter({96: 2, 87: 2, 57: 2, 95: 1, 88: 1, 56: 1})
Posted by: Guest on November-21-2021

Code answers related to "count number of occurence"

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language