python3.6
print (list(filter(lambda x : math.sqrt(x).is_integer(), range(1, 101))))
print (list(filter(lambda x : math.sqrt(x).is_integer(), range(1, 101))))
2017-08-18
def cmp_ignore_case(s1, s2):
x=s1.upper()
y=s2.upper()
if x>y:
return 1
if x<y:
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
x=s1.upper()
y=s2.upper()
if x>y:
return 1
if x<y:
return -1
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
2017-08-17
import math
def is_sqr(x):
y=math.sqrt(x)
if y%1==0:
return x
print filter(is_sqr, range(1, 101))
def is_sqr(x):
y=math.sqrt(x)
if y%1==0:
return x
print filter(is_sqr, range(1, 101))
2017-08-17
class Fib(object):
def __call__(self,num):
l=[0,1]
for i in range(num-2):
l.append(l[i]+l[i+1])
return l
f = Fib()
print f(10)
def __call__(self,num):
l=[0,1]
for i in range(num-2):
l.append(l[i]+l[i+1])
return l
f = Fib()
print f(10)
2017-08-17
从初阶学到现在的中阶,身为一个文科生,学到这里很迷茫,学习进展很慢,但心中有个信念告诉我:不能放弃!
2017-08-17
mport math
def is_sqr(x):
return math.sqrt(x) in range (1,101)
print filter(is_sqr, range(1, 101))
def is_sqr(x):
return math.sqrt(x) in range (1,101)
print filter(is_sqr, range(1, 101))
2017-08-17
from datetime import datetime
def performance(f):
def fn(*args,**kw):
print 'call '+ f.__name__ +' () in '+ str(datetime.now())
return f(*args,**kw)
return fn
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
def performance(f):
def fn(*args,**kw):
print 'call '+ f.__name__ +' () in '+ str(datetime.now())
return f(*args,**kw)
return fn
@performance
def factorial(n):
return reduce(lambda x,y: x*y, range(1, n+1))
print factorial(10)
2017-08-17
class Person(object):
count = 0
def __init__(self, name):
Person.count +=1
self.name = name
p1 = Person('Bob')
print Person.count,
p2 = Person('Alice')
print Person.count,
p3 = Person('Tim')
print Person.count
count = 0
def __init__(self, name):
Person.count +=1
self.name = name
p1 = Person('Bob')
print Person.count,
p2 = Person('Alice')
print Person.count,
p3 = Person('Tim')
print Person.count
2017-08-16
class Person(object):
count = 0
def __init__(self, name):
Person.count +=1
self.name = name
p1 = Person('Bob'),
print Person.count
p2 = Person('Alice'),
print Person.count
p3 = Person('Tim')
print Person.count
count = 0
def __init__(self, name):
Person.count +=1
self.name = name
p1 = Person('Bob'),
print Person.count
p2 = Person('Alice'),
print Person.count
p3 = Person('Tim')
print Person.count
2017-08-16