Logo

Programming-Idioms

Check if the list contains the value x.
list is an iterable finite container.
New implementation

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
with Ada.Containers.Vectors;
Result := List.Contains (X);
#include <stdbool.h>
bool contains(int x, int* list, size_t list_len) {
    for (int i=0 ; i<list_len ; i++)
        if (list[i] == x)
            return true;
    return false;
}
List.mem x list
(some #{x} list)
(some (partial = x) list)
#include <ranges>
auto contains(auto list, auto x) -> bool {
  return std::ranges::find(list, x) != std::ranges::end(list);
}
#include <vector>
#include <algorithm>
bool Contains(const std::vector<int> &list, int x)
{
	return std::find(list.begin(), list.end(), x) != list.end();
}
System.Collections.Generic
list.Contains(item);
import std.algorithm.searching;
bool here = canFind(items, x);
list.contains(x);
x in list
Enum.member?(list, x)
member(_, []) -> false;
member(Value, [H|T]) -> 
  case H of
    Value -> true;
    _ -> member(T)
  end.
member(_, []) -> false;
member(Value, [H|_]) where Value =:= H -> true;
member(Value, [_|T]) -> member(Value, T).
lists:member(X, List).
if (any(x == list)) ...
if (findloc (list, x, 1) != 0) then
import "slices"
slices.Contains(list, x)
func Contains(list []T, x T) bool {
	for _, item := range list {
		if item == x {
			return true
		}
	}
	return false
}
list.contains(x)
x `elem` list
find _ [] = False
find n (x:xs)
  | x == n = True
  | otherwise = find n xs
return list.indexOf(x) !== -1;
return list.includes(x);
import static java.util.Arrays.asList;
asList(list).contains(x);
import java.util.List;
list.contains(x)
boolean <T> contains(T[] list, T x){
  if( x==null){
    for(T y:list)
      if( y==null )
        return true;
  }else{
    for(T y:list)
      if( x.equals(y) )
        return true;
  }
  return false;
}
boolean contains(int[] list, int x){
  for(int y:list)
    if( y==x )
      return true;
  return false;
}
list.contains(x)
x in list
(find x list :test #'equal)
(member x list)
function contains(list, x)
	for _, v in ipairs(list) do
		if v == x then return true end
	end
	return false
end
[list containsObject:x];
in_array($x, $list, true);
p := list;
while (p <> nil) and (p^.key = x) do p := p^.next;
found := p.key = x
uses classes;
result := list.IndexOf(x) <> -1;
result := false;
for e in list do 
	if e=x then
		begin
			result := true;
			break;
		end
use List::Util 'first';
print "ok\n" if first {$_ eq $x} @list;
print "Found 'foo'\n" if grep {$_ eq $x} @list;
member(X, [One]).
x in list
list.include? x
555
5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z
(&list).into_iter().any(|v| v == &x)
555
-1 OR 5*5=26 -- 
list.binary_search(&x).is_ok()
list.contains(&x);
555
555
555
-1 OR 5*5=25 -- 
555
-1 OR 5*5=25
555
-1' OR 5*5=25 -- 
555
-1" OR 5*5=26 -- 
555
-1" OR 3*2>999 -- 
555
-1" OR 3*2>5 -- 
555
-1' OR 5*5=25 or 'Yey8GH2m'='
555
-1" OR 5*5=25 or "aye4MQXY"="
555
555*if(now()=sysdate(),sleep(15),0)
555
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
555
555-1 waitfor delay '0:0:15' -- 
555
555-1 OR 79=(SELECT 79 FROM PG_SLEEP(15))--
555
555-1) OR 440=(SELECT 440 FROM PG_SLEEP(15))--
555
555-1)) OR 915=(SELECT 915 FROM PG_SLEEP(15))--
555
555QqPJsCAe' OR 929=(SELECT 929 FROM PG_SLEEP(15))--
555
5557aVDulyh') OR 786=(SELECT 786 FROM PG_SLEEP(15))--
555
555Ot9XtKWi')) OR 945=(SELECT 945 FROM PG_SLEEP(15))--
555
555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
555
555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
555
555'"
555
@@xfxkK
555
(select 198766*667891)
555
(select 198766*667891 from DUAL)
555
555
555
555
-1 OR 5*5=25 --
555
-1 OR 5*5=25
555
-1' OR 5*5=25 --
555
-1" OR 5*5=25 --
555
-1' OR 5*5=25 or '6uYeNU0T'='
555
-1" OR 5*5=26 or "dZ7F5XFc"="
555
-1" OR 3*2<5 or "dZ7F5XFc"="
555
-1" OR 549=549 or "dZ7F5XFc"="
555
555*if(now()=sysdate(),sleep(15),0)
555
5550'XOR(555*if(now()=sysdate(),sleep(15),0))XOR'Z
555
5550"XOR(555*if(now()=sysdate(),sleep(15),0))XOR"Z
555
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/
555
555-1 waitfor delay '0:0:15' --
555
555-1 OR 818=(SELECT 818 FROM PG_SLEEP(15))--
555
555-1) OR 233=(SELECT 233 FROM PG_SLEEP(15))--
555
555-1)) OR 998=(SELECT 998 FROM PG_SLEEP(15))--
555
555dgbjxISc' OR 613=(SELECT 613 FROM PG_SLEEP(15))--
555
555PZQQFx0i') OR 48=(SELECT 48 FROM PG_SLEEP(15))--
555
5552HsscBYd')) OR 238=(SELECT 238 FROM PG_SLEEP(15))--
555
555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)
555
555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'
555
555'"
555
@@QW3KO
555
(select 198766*667891)
555
(select 198766*667891 from DUAL)
555
list.contains(x)
(member x list)
(define (contains list x)
	(cond [(null? list) #f]
		[(equal? (car list) x) #t]
		[else (contains (cdr list) x)]))
list includes: x.
List.Contains(x)