list.any code example

Example 1: c# list any

List<int> numbers = new List<int> { 1, 2 };
bool hasElements = numbers.Any();
string result = hasElements ? "is not" : "is";

Console.WriteLine($"The list {result} empty.");

// This code produces the following output:
// The list is not empty.

Example 2: any in python

The any() function takes an iterable (list, string, dictionary etc.) in Python.

The any() function returns the boolean value:

True if at least one element of an iterable is true
False if all elements are false or if an iterable is empty

Example:
some_list = [1, 2, 3]
print(any(some_list)) # True
another_list = []
print(any(another_list)) # False