Python filter () function

Source: Internet
Author: User
Tags iterable

The filter () function filters the sequence, filters out elements that are not eligible, returns an iterator object , and, if you want to convert to a list, you can use list () to convert.

The two parameters are received, the first is a function, the second is a sequence, each element of the sequence is passed as a parameter to the function, and then returns True or False, and finally the element that returns true is placed in the new list.

Filter(function, iterable)
    • Beauty /' f?lt?/

      N. filters; [chemical] filters; filter; filters; optical Filters

      Vt. to remove by filtration;

Parameters
    • Function-------judging functions.
    • Iterable--Can iterate over objects.
return value

Returns an Iterator object

# 2. Use the filter function to process the list of numbers and filter out all the even number in the list num = [1,3,5,6,7,8]def  Choice (x):    if x%2 = = 0        :return= filter (choice,num)print(list ( ret))print(list (filter (lambda x:x%2==0,num)))

Python filter () function

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.