Write a Python function to count the number of even numbers from a list of numbers.
Write a Python function that takes a list and returns a new list
with unique elements of the first list.
Sample List : [1,2,3,3,3,3,4,5]
Unique List : [1, 2, 3, 4, 5]
(Be careful with indentation of lines in python. If you still have any doubts regarding this question please comment I will definitely help)
1).
Explanation:
Code to find number of even numbers in a list:
def even_count(x):
count = 0
for i in range(len(x)):
if(x[i]%2==0):
count=count+1
return count
x = [2,3,9,6,5,10,8,12,14]
n = even_count(x)
print("number of even numbers in the list is: ",n)
O/P:
number of even numbers in the list is: 6
Code and O/P screenshot:
Here in the input list there are 6 even numbers. So it prints 6
2).
Code Explanation:
Code to return unique elements of the list:
def unique_list(x):
unique = []
for i in range(len(x)):
if(x[i] not in unique):
unique.append(x[i])
return unique
x = [1,2,3,3,3,3,4,5]
print(unique_list(x))
O/P:
[1, 2, 3, 4, 5]
Code and O/P screenshot:
Get Answers For Free
Most questions answered within 1 hours.