笔记:udacity计算机科学导论- 课程13/2数独正确性判断
2017-12-31 01:26
375 查看
# A list is symmetric if the first row is the same as the first column,
# the second row is the same as the second column and so on. Write a
# procedure, symmetric, which takes a list as input, and returns the
# boolean True if the list is symmetric and False if it is not.
#昨晚数独那题,这一题基本相同,而且,可以减少循环数量。
def symmetric(o):
qq = []
a = 0
while a < len(o):
for p in o:
if len(p) != len(o):
return False
qq.append(p[a])
if o[a] != qq: #o{a]一定不能误写为o(a)
return False
a = a + 1
qq = []
return True
# Your code here
#print symmetric([[1, 2, 3],
# [2, 3, 4],
# [3, 4, 1]])
#>>> True
print symmetric([["cat", "dog", "fish"],
["dog", "dog", "fish"],
["fish", "fish", "cat"]])
#>>> True
#print symmetric([["cat", "dog", "fish"],
# ["dog", "dog", "dog"],
# ["fish","fish","cat"]])
#>>> False
#print symmetric([[1, 2],
# [2, 1]])
#>>> True
#print symmetric([[1, 2, 3, 4],
# [2, 3, 4, 5],
# the second row is the same as the second column and so on. Write a
# procedure, symmetric, which takes a list as input, and returns the
# boolean True if the list is symmetric and False if it is not.
#昨晚数独那题,这一题基本相同,而且,可以减少循环数量。
def symmetric(o):
qq = []
a = 0
while a < len(o):
for p in o:
if len(p) != len(o):
return False
qq.append(p[a])
if o[a] != qq: #o{a]一定不能误写为o(a)
return False
a = a + 1
qq = []
return True
# Your code here
#print symmetric([[1, 2, 3],
# [2, 3, 4],
# [3, 4, 1]])
#>>> True
print symmetric([["cat", "dog", "fish"],
["dog", "dog", "fish"],
["fish", "fish", "cat"]])
#>>> True
#print symmetric([["cat", "dog", "fish"],
# ["dog", "dog", "dog"],
# ["fish","fish","cat"]])
#>>> False
#print symmetric([[1, 2],
# [2, 1]])
#>>> True
#print symmetric([[1, 2, 3, 4],
# [2, 3, 4, 5],
相关文章推荐
- 笔记:udacity计算机科学导论- 课程12/8数独正确性判断
- 笔记:udacity计算机科学导论- 课程11/27-29 for + in/not in 求并集
- 笔记:udacity计算机科学导论- 课程11/23-24 for循环特点
- 笔记:udacity计算机科学导论- 课程11/26 巧用return精简代码
- 笔记:udacity计算机科学导论- 课程15/1-3 初步建立关键字、url对应表
- 笔记:udacity计算机科学导论- 课程14/3
- 笔记:udacity计算机科学导论- 课程11/14-17数组append,+,len的谜题
- 笔记:udacity计算机导论 - 回文判断超简单string[::-1] 课程3-6
- 笔记:udacity计算机科学导论- 课程11/12-14 数组值的改变和增加
- 笔记:udacity计算机科学导论- 课程11/21 各种存储方式比较
- 笔记:udacity计算机科学导论- 课程11/19 python取幂, DRAM 存储原理、容量、速度
- python字母、哈希数字表转换- 笔记:udacity计算机科学导论18/14
- 笔记:udacity计算机导论 - 定义python的procedure 课程5-1、10
- 笔记:udacity计算机导论 - python的if语句课程5-17
- 笔记:udacity计算机导论 - python的while语句课程5-23-25
- MIT开发课程-计算机科学及编程导论-课程简介及数据类型-笔记
- 笔记:udacity计算机科学导论- 函数索引
- 逐渐了解python搜索原理 - 笔记:udacity计算机科学导论18/1-12
- udacity计算机科学导论- 课程11-数组元素
- MIT开发课程-计算机科学及编程导论-列表和可变性、字典、效率简介-笔记