Click here to Skip to main content
15,846,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
def removeDigits(str):
    return str.translate({ord(i): None for i in '0123456789'})

def fileinput():
    with open('constant.txt') as f:
        lines = f.readlines()
    print('Initial string: ', lines)
    res = list(map(removeDigits, lines))
    print('Final string: ', res)
    print('Make string upper or lower?')
    choice = input()
    if choice.upper() == 'UPPER':
    elif choice.lower() == 'lower':
        print('An error has occured')


What I have tried:

Initial string:  ['Geeks123for127Geeks']
Final string:  ['GeeksforGeeks']
Make string upper or lower?

This is the current output. However, after specifying whether I want upper or lower the program crashes saying there is an attribute error. How would I fix this?
Updated 23-Nov-22 0:04am

1 solution

Your res variable is a list of strings. You can't convert a list to upper-case; you need to convert each string within the list to upper-case.

You can do that using the map function[^] again.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900