Python finds a number that is equal to the inverse of the sequence (for example, 28682)

Source: Internet
Author: User

Directly on the code

#coding: Utf-8

def f1 (x):#定义一个函数, find numbers that are equal to the reverse order

If Type (x)!=int:#如果函数参数不是整型, exiting the program

Exit (' must a int type ')

X=STR (x)

Lix=list (x)

Str1= "

I=len (LIX)-1

While I <len (LIX) and I >=0:#循环的作用是将字符串从尾到头重新组合相加一次

Str1=str1+lix[i]

I=i-1

If x==str1:#如果源字符串和转换后的字符串一样, can be determined to find the positive and negative are equal to the number

return x


List1=range (900,1000)

Print filter (f1,list1)#使用filter函数 to filter out the negative numbers.


Execution Result:

[909, 919, 929, 939, 949, 959, 969, 979, 989, 999]


Python finds a number that is equal to the inverse of the sequence (for example, 28682)

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.