Challenge Checkio(python)—初尝python练习网站

最近在找点python语言练习的网站,发现这个网站不错

http://www.checkio.org/ 

页面设计的也比较漂亮,比较适合学习python的语法知识。
不过注册这个网站 开始就得解决一个python问题,不过很简单。

1 #python3.3 is inside
2 def checkio(els):
3 return els
4 
5 if checkio([1, 2, 3, 4, 5, 6]) == 6:
6 print('Done!')

 

对上面的代码 修改checkio中的函数 函数使得输出的是列表里面前上个数的和。

1 def checkio(els):
2 return els[0]+els[1]+els[2] #后面也看见人家写 return sum(els[0:3])
3 if checkio([1, 2, 3, 4, 5, 6]) == 6:
4 print('Done!')

简单修改一个就够了 然后直接registration.

进去以后刷python题目 通关 有点植物大战僵尸的感觉 .
第一个题目 就是Non-unique Elements.



code :

temp=[]
a=len(data)
def checkio(data):
    for n in range(a):
        if data.count(n)>1:
            temp.append(data[n])
            data =temp
return data            

 

后面看到 creative 排名第一的写法 更有创意

def checkio(data):
    return([x for x in data if data.count(x)>1])

这样写的话更简洁,用的是 列表解析 的方法 可以在一行中用一个for循环将所有的值加入到列表中..

posted @ 2014-05-31 11:42  10cl  阅读(10032)  评论(0编辑  收藏  举报