Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
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':
        print(res.upper())
        
    elif choice.lower() == 'lower':
        print(res.lower())
    else:
        print('An error has occured')
    

fileinput()


What I have tried:

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

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?
Posted
Updated 22-Nov-22 23:04pm
v2

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