Created
February 25, 2019 11:54
-
-
Save ayuLiao/7ddbcbd2be00ec2a58db7ab89604ef22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>>crazystring = ‘dade142.;!0142f[.,]ad’ | |
>>> filter(str.isdigit, crazystring) ‘1420142’ #只保留数字 | |
>>> filter(str.isalpha, crazystring) ‘dadefad’ #只保留字母 | |
>>> filter(str.isalnum, crazystring) ‘dade1420142fad’ #只保留字母和数字 | |
#如果想保留数字0-9和小数点’.’ 则需要自定义函数 | |
>>> filter(lambda ch: ch in ‘0123456789.’, crazystring) ‘142.0142.’ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment