def square_of_sum(L):
l=[x*x for x in L]
return sum(l)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
l=[x*x for x in L]
return sum(l)
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-09-01
其实dict就是一个哈希表,and the keys of a hash table can't be a list
2015-08-30
print [x for x in range(100,1000) if str(x)[0] == str(x)[2]]
这个不错,但和题目要求不符啊....
这个不错,但和题目要求不符啊....
2015-08-30
print [m*100+n*10+t for m in range(1,10) for n in range(0,10) for t in range(0,10) if m == t]
L = range(100,1000)
for x in L:
if x/100 == x %10:
print x
L = range(100,1000)
for x in L:
if x/100 == x %10:
print x
2015-08-30
def move(n, a, b, c):
if n==1:
print a,'-->',c
else:
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
if n==1:
print a,'-->',c
else:
move(n-1,a,c,b)
print a,'-->',c
move(n-1,b,a,c)
move(4, 'A', 'B', 'C')
2015-08-30
赶脚他们都好吊啊,
不是t = [x for x in range(0,10)]
就是t=tuple(range(0,10))
赶脚我写的好渣啊,求大神带飞。
不是t = [x for x in range(0,10)]
就是t=tuple(range(0,10))
赶脚我写的好渣啊,求大神带飞。
2015-08-30
因为执行一次L.pop(2)之后,Bart的索引变成了2,所以再执行L.pop(3)会越界,正确的方法是执行两次L.pop(2)。
2015-08-30