SS123 SS123 - 1 year ago 75
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 ???

Answer Source

You're malforming the list, it should be:


Notice the commas

Hope it helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download