Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

count

How to sort a list of objects based on an attribute of the objects?

September 4, 2022 by Tarik

# To sort the list in place… ut.sort(key=lambda x: x.count, reverse=True) # To return a new list, use the sorted() built-in function… newlist = sorted(ut, key=lambda x: x.count, reverse=True) More on sorting by keys.

Categories python Tags count, list, python, sorting Leave a comment

Count the number of occurrences of a character in a string

August 31, 2022 by Tarik

str.count(sub[, start[, end]]) Return the number of non-overlapping occurrences of substring sub in the range [start, end]. Optional arguments start and end are interpreted as in slice notation. >>> sentence=”Mary had a little lamb” >>> sentence.count(‘a’) 4

Categories python Tags count, python, string Leave a comment

How to efficiently count the number of keys/properties of an object in JavaScript

August 27, 2022 by Tarik

To do this in any ES5-compatible environment, such as Node.js, Chrome, Internet Explorer 9+, Firefox 4+, or Safari 5+: Object.keys(obj).length Browser compatibility Object.keys documentation (includes a method you can add to non-ES5 browsers)

Categories javascript Tags count, javascript, key, performance, properties Leave a comment

How do I count the occurrences of a list item?

August 27, 2022 by Tarik

If you only want a single item’s count, use the count method: >>> [1, 2, 3, 4, 1, 4, 1].count(1) 3 Important: this is very slow if you are counting multiple different items Each count call goes over the entire list of n elements. Calling count in a loop n times means n * n … Read more

Categories python Tags count, list, python Leave a comment
Newer posts
← Previous Page1 … Page20 Page21

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa