I am trying to make an if statement inside a lambda but the catch is I also trying to make all odd numbers to the third too, the lambda line is ignoring the i**3,
#
numbers = range(1,10)
odd_numbers_to_the_third_2 = list(filter(lambda i : i**3 if i%2!=0 else None , numbers))
#
in the second line of the code I am trying to i**3 if its an odd number but the result shows the odd numbers without making it **3 I get [1,3,5,7,9] instead of [1,27,125,343,729]
Aucun commentaire:
Enregistrer un commentaire