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

    Apr 8, 2010 · Given a single item, how do I count occurrences of it in a list, in Python? A related but different problem is counting occurrences of each different element in a collection, getting …

  2. How to sort Counter by value? - python - Stack Overflow

    Other than doing list comprehensions of reversed list comprehension, is there a pythonic way to sort Counter by value? If so, it is faster than this: >>> from collections import Counter &...

  3. How to add or increment single item of the Python Counter class

    How to add or increment single item of the Python Counter class Asked 10 years, 5 months ago Modified 4 years, 3 months ago Viewed 103k times

  4. How do I measure elapsed time in Python? - Stack Overflow

    The python cProfile and pstats modules offer great support for measuring time elapsed in certain functions without having to add any code around the existing functions.

  5. Using a dictionary to count the items in a list - Stack Overflow

    I want a dictionary that counts how many times each item appears in the list. So for the list above the result should be: {'apple': 2, 'red': 3, 'pear': 1} How can I do this simply in Python? If you …

  6. Behaviour of increment and decrement operators in Python

    Sep 28, 2009 · Also, be aware that, in Python, += and friends are not operators that can be used in expressions. Rather, in Python they are defined as part of an "augmented assignment …

  7. Python: Collections.Counter vs defaultdict (int) - Stack Overflow

    79 Both Counter and defaultdict(int) can work fine here, but there are few differences between them: Counter supports most of the operations you can do on a multiset. So, if you want to use …

  8. What is a good way to do countif in Python - Stack Overflow

    I want to count how many members of an iterable meet a given condition. I'd like to do it in a way that is clear and simple and preferably reasonably optimal. My current best ideas are: sum(

  9. python - Counter () subtract - Stack Overflow

    Dec 27, 2017 · As the comments on the question point out, the subtract method is applied to its object in place and returns None. To get the behaviour you want you can either use the - …

  10. How to find the count of a word in a string - Stack Overflow

    I have a string "Hello I am going to I with hello am". I want to find how many times a word occur in the string. Example hello occurs 2 time. I tried this approach that only prints characters - def