def square_of_sum(L):
return [i*i for i in L]
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
return [i*i for i in L]
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2018-05-07
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2018-05-07
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x,y in s:
print x,':',y
for x,y in s:
print x,':',y
2018-05-07
months = set(['Jan','Feb','Mar'])
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
x1 = 'Feb'
x2 = 'Sun'
if x1 in months:
print 'x1: ok'
else:
print 'x1: error'
if x2 in months:
print 'x2: ok'
else:
print 'x2: error'
2018-05-07
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name,':',d[name]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name,':',d[name]
2018-05-07
# -*- coding: utf-8 -*-
d = {
'Adam': '95',
'Lisa':'85',
'Bart': '59'}
score=input()
for key,value in d.items():
if score==d.get(key):
print(key)
d = {
'Adam': '95',
'Lisa':'85',
'Bart': '59'}
score=input()
for key,value in d.items():
if score==d.get(key):
print(key)
2018-05-07
我还以为insert(1,‘Paul’)中‘1’所在的那一位是列表下标的意思,加负号的意思是倒着数,即‘1’的意思是L[1],即列表L中的第二位元素,‘-1’的意思是L[-1],即列表L中的倒数第二位元素
2018-05-07
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for a in d.values():
sum=sum+a
p=sum/len(d)
print p
sum = 0.0
for a in d.values():
sum=sum+a
p=sum/len(d)
print p
2018-05-07
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(3)
L.pop(2)
print L
L.pop(3)
L.pop(2)
print L
2018-05-06
print [100*x+10*y+z for x in range(1,10) for y in range(0,10) for z in range(1,10) if x==z]
2018-05-06
def greet(param='world'):
print 'Hello, %s.' % param
greet()
greet('Bart')
print 'Hello, %s.' % param
greet()
greet('Bart')
2018-05-06
def generate_tr(name, score):
if score< 60 :
return '<tr><td>%s</td><td><td style="color:red">%s</td></tr>' % (name, score)
else:
return'<tr><td>%s</td><td>%s</td></tr>'% (name, score)
tds = [generate_tr(name,score) for name,score in d.iteritems()]
if score< 60 :
return '<tr><td>%s</td><td><td style="color:red">%s</td></tr>' % (name, score)
else:
return'<tr><td>%s</td><td>%s</td></tr>'% (name, score)
tds = [generate_tr(name,score) for name,score in d.iteritems()]
2018-05-06
def move(n, a, b, c):
if n ==1:
print a,'-->',c
return
move(n-1, a, c, b)
move(1, a, b, c)
move(n-1, b, a, c)
move(4, 'A', 'B', 'C')
if n ==1:
print a,'-->',c
return
move(n-1, a, c, b)
move(1, a, b, c)
move(n-1, b, a, c)
move(4, 'A', 'B', 'C')
2018-05-06