Challenge Checkio (python)-python exercise website

Source: Internet
Author: User

 

Recently looking for a site for python language exercises, found this site is good http://www.checkio.org/
The page design is also pretty, and it is suitable for learning python syntax knowledge.
However, when registering this website, you have to solve a python problem, but it is very simple.

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

 

Modify the checkio function in the above Code so that the output is the sum of the number in front of the list.

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! ')

 

Simply modify one and then directly registry.

After entering the course, I felt like a zombie in the plant war.
The first question is 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 =tempreturn data            

 

The ranking one in creative is more creative.

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

This method is more concise. You can use a for Loop in a row to add all the values to the list ..

The above is just a good website to share with you how to learn python. Low technical content, light spray.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.