print [a*100+b*10+c for a in range(1,10) for b in range(0,10) for c in range(1,10) if a==c]
2015-05-17
print 'Adam:',d['Adam']
print 'Lisa:',d['Lisa']
print 'Bart:',d['Bart']
print 'Lisa:',d['Lisa']
print 'Bart:',d['Bart']
2015-05-17
for key,value in d.items():
print key,':',value
#结果为#lisa : 85
#adam : 95
#bart : 59
并不是初始化序列,因为dic是无序的
可以把key和value分开成list,然后zip(key,value)
keys = ["adam", "lisa", "bart"]
values = ["95", "85", "59"]
for key,value in zip(keys, values):
print key,":",value
print key,':',value
#结果为#lisa : 85
#adam : 95
#bart : 59
并不是初始化序列,因为dic是无序的
可以把key和value分开成list,然后zip(key,value)
keys = ["adam", "lisa", "bart"]
values = ["95", "85", "59"]
for key,value in zip(keys, values):
print key,":",value
2015-05-16
for x in xrange(10):
for y in xrange(10):
if x>0 and x<y:
print x*10+y
for y in xrange(10):
if x>0 and x<y:
print x*10+y
2015-05-16
for x in ['1','2','3','4','5','6','7','8','9']:
for y in ['2','3','4','5','6','7','8','9']:
if x<y:
print x+y
for y in ['2','3','4','5','6','7','8','9']:
if x<y:
print x+y
2015-05-16
sum = 0
x = 1
n = 1
while True:
sum+=x
x=x*2
if x>2**19:
break
print sum
x = 1
n = 1
while True:
sum+=x
x=x*2
if x>2**19:
break
print sum
2015-05-16
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print '%s:%s'%(x[0],x[1])
for x in s:
print '%s:%s'%(x[0],x[1])
2015-05-16