特殊函数练习
lambda、filter、map
l1=[ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ]
def isoushu(a):
if(a%2==0) :
return True
else :
return False
it=iter(l1)
def filter(isoushu, it) :
a=[ ]
for i in it:
if isoushu(i):
a.append(i)
return a
dd=range(1, 11)
dd=list(dd)
out=filter(lambda x: x%2==0, dd)
list(out)
out2=map(lambda x: x**2 , dd)
l2=range(1, 101)
l2=list(l2)
t1=filter(lambda x: (x**0 .5)%1==0, l2)
t2=map(lambda x: x**2 , dd)
print(list(t1))
print(list(t2))
def func(a, b) :
if(b==1) :
return a%10000
elif(b%2==0) :
b=b/2
return func(a, b)*func (a, b)%10000
elif(b%2!=0) :
b=(b- 1)/2
return func(a, b)*func (a, b)*a %10000
print(func(7777, 7777))
s="hello world"
def reverse(s):
s1=[ ]
n=len(s)
for i in range(1, n+1) :
s1+=s[ n- i]
return ''.join(s1)
print(reverse(s))
s2=list(s)
s2.reverse()
print(''.join(s2))