I am trying to find the mean of a list that contains the types int, float, and str. When I iterate through and print each item, the code works.
mylist = ["hello", 89.21, -3, "goodbye", 21, 0.0056, -12.34, "thank you", "please", 999.44409]
newlist = []
for i in mylist:
print(i)
and the result is
hello
89.21
-3
goodbye
21
0.0056
-12.34
thank you
please
999.44409
But then when I try to operate on each "i" it gives me the error "TypeError: 'float' object is not iterable". I am trying to iterate over each item, not each character.
for i in mylist:
if type(i)== int or type(i)== float:
newlist += i
Can anyone steer me in the right direction?