filter(None,list) in python als filters out zero`s?

Ive encountered a small issue in ironpython. When I use the underneath code it filters out the Nonetypes. This should also work with filter(). But when I use the filter() function to do this is also filters the zeros from the list…
I expect it to only filter out the None`s…
Did anyone have the same issue or am missing something?

for it in itm:
if it is None: break
#itm4 = filter(None,itm)

hi @wouter.hilhorst

replace your python code above with this:

 Exceldata_Y_1 = list()

 for it in itm:
     if it != None:
1 Like

Hi, That also works and is already a bit shorter, thanks!
But the solution with the T counter in my original code also works.
The problem is that the filter() should also work but doesnt. It filters out the nonetypes AND the zeros which it shouldn`t in my opinion?
Wouter Hilhorst

you are using filter incorrectly, the syntax is

filter(function, iterable)

please use the following:

itm4 = filter(lambda x: x != None, itm)

Thanks, that works!

Please mark my answer as the solution if it solves your question. Thanks.

1 Like