Counting regex pattern matches in one line using sed or grep?
You could use grep -o then pipe through wc -l: $ echo “123 123 123” | grep -o 123 | wc -l 3
You could use grep -o then pipe through wc -l: $ echo “123 123 123” | grep -o 123 | wc -l 3
As mentioned in THIS ANSWER using operator.countOf() is the way to go but you can also use a generator within sum() function as following: sum(value == 0 for value in D.values()) # Or the following which is more optimized sum(1 for v in D.values() if v == 0) Or as a slightly more optimized and … Read more
There is currently no API for the hashtags feature on Facebook edit: there was however a public posts search function which will return some public posts with a certain hashtag if you use that hashtag as the search string in API version 1.0 – there is no equivalent in version 2.0 onwards It ignores the … Read more
You can use array_count_values function $array = array(‘apple’, ‘orange’, ‘pear’, ‘banana’, ‘apple’, ‘pear’, ‘kiwi’, ‘kiwi’, ‘kiwi’); print_r(array_count_values($array)); will output Array ( [apple] => 2 [orange] => 1 [pear] => 2 etc… )
Here’s another option: s=”some string” numbers = sum(c.isdigit() for c in s) letters = sum(c.isalpha() for c in s) spaces = sum(c.isspace() for c in s) others = len(s) – numbers – letters – spaces
Two things come to my mind: std::count_if and then compare the result to 1. To avoid traversing the whole container in case eg the first two elements already match the predicate I would use two calls looking for matching elements. Something along the line of auto it = std::find_if(begin,end,predicate); if (it == end) return false; … Read more
SELECT foo, count(bar) FROM mytable GROUP BY bar ORDER BY count(bar) DESC; The group by statement tells aggregate functions to group the result set by a column. In this case “group by bar” says count the number of fields in the bar column, grouped by the different “types” of bar. A better explanation is here: … Read more