About 99,800 results
Open links in new tab
  1. python - How do I count the occurrences of a list item? - Stack …

    Apr 8, 2010 · >>> l = ["a","b","b"] >>> l.count("a") 1 >>> l.count("b") 2 Counting the occurrences of all items in a list is also known as "tallying" a list, or creating a tally counter. Counting all items …

  2. python - Count the number of occurrences of a character in a …

    Jul 20, 2009 · str.count(a) is the best solution to count a single character in a string. But if you need to count more characters you would have to read the whole string as many times as …

  3. python - Count occurrences of a substring in a list of strings

    Aug 17, 2017 · d_count = data.count('foo') print("d_count:", d_count) produces: d_count: 0 but I expect to get: d_count: 2 I also tried doing: d_count = data.count(any('foo' in s for s in data)) …

  4. Python: count repeated elements in the list - Stack Overflow

    Apr 23, 2014 · I am trying to find a simple way of getting a count of the number of elements repeated in a list e.g ...

  5. python - Count letter differences of two strings - Stack Overflow

    Sep 1, 2012 · You can use the built-in zip function or itertools.izip to simultaneously iterate over both strings, while the latter is a little more performant in case of huge input. If the strings are …

  6. python - Letter Count on a string - Stack Overflow

    May 28, 2010 · Python newb here. I m trying to count the number of letter "a"s in a given string. Code is below. It keeps returning 1 instead 3 in string "banana". Any input appreciated. def …

  7. Counting number of strings in a List with Python

    Jun 7, 2015 · [once][2] [thus][2] [one][2] [count][1] [this][1] If you want the data alphabetically from lowest to highest and from highest to lowest for the count you need to pass a key -x[1] to …

  8. python - Count number of occurrences of a substring in a string

    def substr_count(st, sub): # If a non-overlapping substring then just # use the standard string `count` method # to count the substring occurences if sub[0] != sub[-1]: return st.count(sub) # …

  9. How to get the size (length) of a string in Python

    Aug 31, 2023 · Then you can convert it to unicode object and get character count: >>> print(len('йцы'.decode('utf8'))) #String contains Cyrillic symbols 3 B. The sys.getsizeof() …

  10. python - Count string values inside a string/list (FOR Loop) - Stack ...

    Apr 29, 2013 · Use a for loop to count how many times the letter 'a' appears in the string 'fanta'. Check your answer using Python’s string method called count(). Note: I am aware the question …

Refresh