0

I am trying the following lines to keep only the digits

>>> s = "H3ll0 P30P13"
>>> filter(lambda x: x.isdigit(), s)
'303013'

But what I got is not '303013' but I got <filter at 0x1888b671408>. I am using Spyder IDE

quamrana
  • 37,849
  • 12
  • 53
  • 71
YasserKhalil
  • 9,138
  • 7
  • 36
  • 95
  • 1
    `filter` method in python returns `iterator` that is filtered from the input. we can get the vaue by converting to list and join with space `"".join(list(filter(lambda x: x.isdigit(), s)))`. Hope this helps – Kumar KS Nov 01 '20 at 18:38
  • 1
    Thanks a lot. The same answer like @Franco Piccolo – YasserKhalil Nov 01 '20 at 18:40

1 Answers1

3

Try:

''.join(filter(lambda x: x.isdigit(), s))
Franco Piccolo
  • 6,845
  • 8
  • 34
  • 52