аватар question@mail.ru · 01.01.1970 03:00

How to withdraw an even number from the list if all other values ​​are odd, and vice versa?

lists can be two types, with all the even numbers and one odd, and with all the odd numbers and one one. There can be at least three values ​​in the list.

lists for example:

  [ 2 ,  4 ,  0 ,  100 ,  4 ,  11  2602 ,  36 ] # must deduce 11 (as one odd)   [ 160 ,  3 ,  1719 ,  19 ,  11 ,  13 , - 21 ] # must take 160 (like one thing even)      

how to write a code so that one different number is displayed?

аватар answer@mail.ru · 01.01.1970 03:00

for example (provided that there are 3 elements, otherwise it is impossible to determine what is more):

  res = [ max ,  min ] [ sum  (x %  2   for  x  in  l [:  3 ]) & gt;  1 ] (l, key =  lambda  x: x %  2 )                                       

Latest

Similar