Python clears useless characters from a string

Source: Internet
Author: User

Remove illegal characters contained in list Val_list, Illegal_char is a list of illegal characters

Def clear ():
Illegal_char = [' ', ' # ', '% ', ' _ ', ' @ ']
Tmp_list = []
Val_list = [' Aaaaaaaa a A a 1%dddd%[email protected]@@@@@111 #111 ', ' bbbbbbbbb_ggg_g_g-bbls## 222222222222###-']
For I in Illegal_char:
For J in Val_list:
val = re.sub (i, ", j)
Tmp_list.append (Val) # Remove the first type of illegal word specifier (such as ' # ') to add all the data to a temporary list tmp_list
Val_list = [] # empties the list of previously stored data and then puts the cleansed data back into the data list val_list
Val_list = Tmp_list
Tmp_list = [] # to avoid cleaning up once to add data to the temporary list causes the number of cleanup times to double the data, all to erase the tmp_list
Return val_list
Print Clear ()

Python clears useless characters from a string

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.