Can you solve this python trick | Sololearn: Learn to code for FREE!

+9

Can you solve this python trick

this is Python code X=('123abc') how we can print only digits in this string and we assume that we don't know the positions of the digits we know this is alnum statement but how can we print only digits

2/9/2018 11:56:59 AM

Maninder $ingh

7 Answers

New Answer

+13

Google : RegEx. #this thing is really overpowered...

+7

x = "123abc" y = list(filter(lambda x: x.isdigit(), x)) print( "".join(y) )

+4

this will work! x = '123abc' #every thing in printable will be printed only printable = '1234567890' for ch in x: if ch not in printable: x = x.replace(ch, "") print(x)

+4

x='123abc' print(*[i for i in x if i.isdigit()],sep='')

+3

Nice answer @Fred

+3

Using the isdigit() method. for i in X: if i.isdigit (): print (i)

+2

@fred,is it(ur answer )python?