Situatie
Demonstrating to check the existence of an element in the list using the Naive method and in .
Solutie
test_list
=
[
1
,
6
,
3
,
5
,
3
,
4
]
print
(
"Checking if 4 exists in list ( using loop ) : "
)
# Checking if 4 exists in list
# using loop
for
i
in
test_list:
if
(i
=
=
4
) :
print
(
"Element Exists"
)
print
(
"Checking if 4 exists in list ( using in ) : "
)
# Checking if 4 exists in list
# using in
if
(
4
in
test_list):
print
(
"Element Exists"
)
Output:
Checking if 4 exists in list ( using loop ) : Element Exists Checking if 4 exists in list ( using in ) : Element Exists
Leave A Comment?