a1=1
b1=5
print a1 an d b1 #打印结果为5
a2=0
b2=5
print a2 an d b2 #打印结果为0
a3=1
b3=5
print a3 or b3 #打印结果为1
a4=0
b4=5
print a4 or b4 #打印结果为5
a5=0
print not a5 #打印结果true
a6=1
print not a6 #打印结果False
|
class Solution(object):
"""
输入:
[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9,10,11, 12],
[13,14,15,16],
]
输出:[1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10]
"""
def spiralOrder(self, matrix):
ret=[]
if not matrix: return []
top=0
bottom =len(matrix)-1 #底部边界
left=0
right=len(matrix[0])-1 #右边界
while(True):
#从左到右
for i in range(left,right+1):
ret.append(matrix[top][i])
top+=1
if (left>right or top >bottom): break #无法判断哪步越界
#从上到下
for i in range(top,bottom+1):
ret.append(matrix[i][right])
right-=1
if (left > right or top > bottom): break #无法判断哪步越界
#从右到左
for i in range(right,left-1,-1):
ret.append(matrix[bottom][i])
bottom-=1
if (left > right or top > bottom): break # 无法判断哪步越界
#从下到上
for i in range(bottom,top-1,-1):
ret.append(matrix[i][left])
left+=1
if (left > right or top > bottom): break # 无法判断哪步越界
return ret
|
n=[[0]*3 for i in range(10)]
print n
|
[[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]]
|
热门关键词: 登录