Reversing a number using list in python -


i want reverse number error:

"typeerror: 'type' object not subscriptable"

i grateful if correct code.here code:

number=input("enter number ") num=int(number) count=0 list1=[] while(num!=0):     list1.append(num%10)     num=num//10     count=count+1 print(list1[::-1]) k=len(list1) after=0 h in range(k):     after+=int(list[h])*(10**h)     h=-1 print(after) 

you can using list's (create, reverse, join):

''.join(map(str, list(reversed(list(str(num)))))) 

or just, easier:

int(str(num)[::-1]) 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -