python-tutorial-Python-courses-python-exercises

Exercise 45

Write a Python algorithm as a function which takes as parameter a list of real numbers L and which returns the list obtained from L by removing all integers.

Solution

# Function which removes integers from a list
def removeInt (L):
# initialize the list obtained from L by removing all integers
l_remove_int = []

for x in L:
if (type (x) != int):
l_remove_int.append (x)
return l_remove_int

# Example:
L = [11.5, 0, 7.75, 8, 23.97, 16, 10, 14.5]
print (removeInt (L)) # output: [11.5, 7.75, 23.97, 14.5]
Younes Derfoufi
my-courses.net

Leave a Reply