+ 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.

14th Jun 2020, 12:32 PM
Vasudev Dubey
Vasudev Dubey - avatar
6 ответов
+ 7
Works fine just it's string numbers in list ,use int(input()) instead for converting string to integer as input returns string
14th Jun 2020, 12:59 PM
Abhay
Abhay - avatar
+ 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()))
14th Jun 2020, 12:57 PM
Ipang
+ 3
Ok
14th Jun 2020, 1:13 PM
Vasudev Dubey
Vasudev Dubey - avatar
+ 3
Thanks Ipang
14th Jun 2020, 1:13 PM
Vasudev Dubey
Vasudev Dubey - avatar
+ 3
Thanks @Abhay
14th Jun 2020, 1:14 PM
Vasudev Dubey
Vasudev Dubey - avatar
+ 2
res = [x for x in lst if x % 2 == 0]
14th Jun 2020, 12:46 PM
Slick
Slick - avatar