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


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


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


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


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)


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


Nice answer @Fred


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


@fred,is it(ur answer )python?