number=input("Enter a number :)
sum=0
while number > 0 :
rem=number % 10
sum =sum + rem
number=number /10
print sum
Solution 1:
list1=[1,2,1,3] count={} for item in list1 : print item if item not in count: #check if item is in list count[item]=0 #if no then set item key value print count[item] count[item]+=1 #yes increment print count[item] print count
def cube(x): return x*x*x
res=map(cube, range(1, 11))
print res
#! python
# reduce(func, sequence)" returns a single value constructed by
# calling the binary function func on the first two items of the sequence,
# then on the result and the next item, and so on
def add(x,y): return x+y
r=reduce(add, range(1, 11))
print r # 55
queue = ["Eric", "John", "Michael"] queue.append("Terry") # Terry arrives queue.append("Graham") # Graham arrives print queue s=queue.pop(0) print s s=queue.pop(0) print s print queue [deleting elements from list] a = [-1, 1, 66.6, 333, 333, 1234.5] del a[0] print a del a[2:4] print a