Python Practice function 3

Source: Internet
Author: User

Exercises:

    1. Use lambda and filter to complete the following functions: Output a list containing all the even numbers within 1-100. (Hint: can use FILTER,LAMBDA)

      [ x for x in range(1,101) if x%2==0]
      def func(x):    return x % 2 == 0new_list = list(filter(func, range(1, 101)))print(new_list)
    2. With location matching, keyword matching, collection matching (tuple collection, dictionary collection) write 4 functions, complete the function;

      Pass 3 List parameters:

      [1,2,3],[1,5,65],[33,445,22]

      Returns the largest of the 3 elements in the list, with the result: 445

      def get_max(list1, list2, list3):    return max(list1+list2+list3)print get_max([1,2],[3,4],[67,9])def get_max2(list1=[], list2=[], list3=[]):    return max(list1+list2+list3)print get_max2([1,2],[3,4],[67,9])def get_max3(*list):    a = []    for x in list:        a.extend(x)    return max(a)print(get_max3([1,2,3],[4,6,8]))def get_max4(**list):    new_list = []    for x in list.values():        new_list.extend(x)    return max(new_list)print(get_max4(list1=[1,2,3],list2=[4,6,8]))

Python Practice function 3

Related Article

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.