Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
>>> def count_of_elements_containing_pattern(list_of_strings, pattern):
return [pattern in string for string in list_of_strings].count(True)
>>> my_list = ["foo", "bar", "baz", "spam", "eggs", "foobar"]
>>> count_of_elements_containing_pattern(my_list, "foobar")
1
>>> count_of_elements_containing_pattern(my_list, "foo")
2
>>> count_of_elements_containing_pattern(my_list, "bar")
2
>>> count_of_elements_containing_pattern(my_list, "a")
4
>>> count_of_elements_containing_pattern(my_list, "z")
1
>>> count_of_elements_containing_pattern(my_list, "oo")
2
>>> import pandas as pd
>>> my_list = ["foo", "bar", "baz", "spam", "eggs", "foobar"]
>>> my_series=pd.Series(my_list)
>>> my_series[my_series.str.match("foobar")].count()
1
>>> my_series[my_series.str.match("foo")].count()
2
>>> my_series[my_series.str.match(".*bar")].count()
2
>>> my_series[my_series.str.match(".*a.*")].count()
4
>>> my_series[my_series.str.match(".*z.*")].count()
1
>>> my_series[my_series.str.match(".*oo.*")].count()
2