how to replace the characters of the list in python
Question: I want to write a code in python that will replace every every small letter
character with "a" , every capital letter with "A" and every digit with 0. I
write code but it caused an error of **x not in list** , code is below

    
    
    tokens = ["apple","banana","Orange", "pineApple", "10nuts"]
    for token in tokens:
        for ch in token:
            if ch.islower():
                loc = tokens.index(ch)
                tokens.remove(ch)
                tokens.insert(loc,'a');
            elif ch.isupper():
                loc = tokens.index(ch)
                tokens.remove(ch)
                tokens.insert(loc,'A');
            elif ch.isdigit():
                loc = tokens.index(ch)
                tokens.remove(ch)
                tokens.insert(loc,'0');
    for t in tokens:
        print t
    


Answer: Using [regular expressions](https://docs.python.org/2/library/re.html):

    
    
    from re import sub
    
    tokens = ["apple","banana","Orange", "pineApple", "10nuts"]
    
    for i, token in enumerate(tokens):
        token = sub(r'[A-Z]', 'A', token)
        token = sub(r'[a-z]', 'a', token)
        token = sub(r'\d', '0', token)
        tokens[i] = token
    
    print tokens
    ## Output: ['aaaaa', 'aaaaaa', 'Aaaaaa', 'aaaaAaaaa', '00aaaa']
    

