1. 11.The number of end 0

    def count(num,i):
        if num==0:
            return 0
        if num%i==0:
            return 1+count(num/i,i)
        else:
            return 0
    
    def countzero(list):
        count2=0
        count5=0
        for i in range(len(list)):
            count2 += count(list[i], 2)
            count5 += count(list[i], 5)
    
        if count2>count5:
            return count5 ...
    read more
  2. 3.Reverse a string

    a="12345"
    
    # method 1
    print(a[::-1])
    
    # method 2
    from functools import reduce
    print reduce((lambda x, y: y+x), a)   # reduce is [ func(func(s1, s2),s3), ... , sn ]
    
    # method 3
    print "".join(reversed(a))     # reversed(object) return a iterator, type 'reversed', join(iterable)
    
    read more

« Page 21 / 23 »

blogroll

social