Light Mode
Dark Mode
Removing non alphanumeric characters

Hi all,

Even though this is a beginners task, I find it rather complicated to write the actual code.

The first step is to remove the non alphanumeric characters. I found the following by searching:

import string

def mystrip(strg):
    """
    Strips bad characters from a string.
    """
    bad_chars = """[!@#$ -,)(*&^%<>?/\r\n"|{}=+.]:; """
    return strg.translate(string.maketrans("", "", ), bad_chars)

Unfortunatly this code does not work as expected. Can someone help me with this assignment/code?

Created: March 29, 2016, 6:31 p.m.
Updated: March 30, 2016, 6:26 p.m.
0
11
User avatar
Hayertjez