| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1430 人关注过本帖
标题:新手求助一个关于define function的问题
只看楼主 加入收藏
GodBlessMe
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-8-27
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
新手求助一个关于define function的问题
Implement a Python function called validate_image(image) which takes an image as its argument and returns True if the image is valid and False otherwise. An image is valid if it satisfies all the following conditions:
• It is a list of lists of integers only (no other types are valid).
• All rows in the image are of the same length (the image is rectangular). • Allintegersiintheimagelieintherange0≤i≤255.
You can test if an object is a list or an integer using the type function like so:
   >>> type(1) == int
   True
   >>> type(True) == int
   False
   >>> type([1,2,3]) == list
   True
   >>> type(None) == list
   False
Below are some example applications of the valid_image function:
   >>> validate_image([]) # the empty image is valid
   True
   >>> validate_image([1]) # not a list of lists of integers
   False
   >>> validate_image(None) # not a list at all
   False
   >>> validate_image([[0,23,97,45], [125,3,12,1], [8,8,8,8]])
   True
   >>> validate_image([[1,2,3], [4,5]]) # rows different length
   False
   >>> validate_image([[1,2,3], [4,5,256]]) # 256 > maximum intensity
   False
搜索更多相关主题的帖子: only following otherwise function 
2012-08-27 13:39
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:10 
没看明白问题和后面说的有什么关系……
2012-08-30 01:49
liuxufeng
Rank: 2
等 级:论坛游民
帖 子:10
专家分:10
注 册:2012-7-30
收藏
得分:10 
和ls同样的问题

按照解释不就是那样吗
2012-09-01 19:02
快速回复:新手求助一个关于define function的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016859 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved