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

empty-list

How can I make multiple empty lists in Python? [duplicate]

May 29, 2023 by Tarik

A list comprehension is easiest here: >>> n = 5 >>> lists = [[] for _ in range(n)] >>> lists [[], [], [], [], []] Be wary not to fall into the trap that is: >>> lists = [[]] * 5 >>> lists [[], [], [], [], []] >>> lists[0].append(1) >>> lists [[1], [1], [1], … Read more

Categories python Tags empty-list, list, python Leave a comment

Why use null function instead of == [] to check for empty list in Haskell?

March 22, 2023 by Tarik

You should use null. In most cases it doesn’t matter, but it is a good habit to get into anyway, because occasionally you may want to check if a list of non-comparable things is empty. Here is a short, crisp example showing this difference: > null [id] False > [id] == [] <interactive>:1:1: error: • … Read more

Categories list Tags empty-list, haskell, is-empty, list Leave a comment

Is there an “Empty List” singleton in C#?

January 19, 2023 by Tarik

You are looking for Enumerable.Empty<T>(). In other news the Java empty list sucks because the List interface exposes methods for adding elements to the list which throw exceptions.

Categories c# Tags c++, empty-list, ienumerable, singleton Leave a comment

Collections.emptyList() vs. new instance

October 3, 2022 by Tarik

The main difference is that Collections.emptyList() returns an immutable list, i.e., a list to which you cannot add elements. (Same applies to the List.of() introduced in Java 9.) In the rare cases where you do want to modify the returned list, Collections.emptyList() and List.of() are thus not a good choices. I’d say that returning an … Read more

Categories java Tags collections, empty-list, java Leave a comment

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