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

Hi,
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?

T=0
for it in itm:
if it is None: break
T+=1
#itm4 = filter(None,itm)
Exceldata_Y_1.append(itm[0:T])

hi @wouter.hilhorst

replace your python code above with this:

 Exceldata_Y_1 = list()

 for it in itm:
     if it != None:
         Exceldata_Y_1.append(it)
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