SS123 SS123 - 5 months ago 34
Python Question

Python filter() function and list comparison

I have a list in python like

and i need to filter out the value of A,B,C,D so i wrote a code like follow

list(filter(lambda x:x.isalpha(),l))

then returned
['A', 'C']

it did't return value B and D so i thought it was some thing i don't know about python filter function then i wrote it in list comparison like follows

[i for i in l if i.isalpha()]

but the strange thing is it also return the
['A', 'C']
so every time what happen to the value B and D

Any one can explain me how to filter all alphabetic values out ???


You're malforming the list, it should be:


Notice the commas

Hope it helps!