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

How to add a condition to the list generator?

I tried to do so, but it does not work

  a = [ int  ( for  i  in   range  ( 5 )  if  i %  10  ==  0 ]     

that is, you need to add a condition so that only the numbers are added by 10 without a trace

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

Divide reading and filtering:

  a = [i  for  i  in  ( int  ( input  ())  for  _  in   ( 5 ))  if  i %  10  ==  0 ]   #----------------------------------- ================================ /-----------   # ^ We read five whole numbers ^   # |                                             |#        -----------------------------------------------#                   отбираем кратные Ten   

the same in parts:

  # We read five integers   # Important: we do not read them. The generator does not read anything until they ask him.  G = ( int  ( input  for  _  in    range  ( 5 ))  # Class = ""> in  g  if  i %  10  ==  0 ]                                       

Latest

Similar