+ 1
Can anyone tell me, what is the wrong thing in this coding??
n = int(input()) lst = [] for i in range(0,n): lst.insert(i, input()) print("list:", lst) res = list(filter(lambda x: x%2 ==0, lst)) print(res) Here, I want to extract even numbers from my list.
6 Respuestas
+ 7
Works fine just it's string numbers in list ,use int(input()) instead for converting string to integer as input returns string
+ 4
You need to convert input to number first. `input()` function returns a string, you can't check even/odd on a string.
for i in range(n):
lst.insert(i, int(input()))
+ 3
Ok
+ 3
Thanks Ipang
+ 3
Thanks @Abhay
+ 2
res = [x for x in lst if x % 2 == 0]