Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

string editing on specific request split.upper/.lower

I’m trying to figure out how to edit the below to have a option to convert lower/upper(abc = ABC) I’d like to have a specific input that it knows to convert to the other. so input might be "convert_upper" the program now knows I want to convert the next input "abc" into " ‘A’, ‘B’, ‘C’ "

I’ve made it pretty far into this endeavor through forums but figuring out how to get the input1 to take a "special request" and do upper/lower based on that input has thrown me for loop
Also I was curious how I can create the list. (a 2nd input that confirms the name for the list something like . . . )

example in/output^

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

input1 = numbers
 numbers = [] 
input2 = 123
numbers = ['1', '2', '3']

current code takes input such as "abc 123 !@#" and outputs a list [‘a’, ‘b’, ‘c’, ‘ ‘, ‘1’, ‘2’, ‘3’, ‘ ‘, ‘!’, ‘@’, ‘#’]

def split(word):
    return list(input1)
input1 = input("enter Letters, Numbers or Symbols: ")
print(split(input1))

>Solution :

Here’s one approach: have a function that you apply to the input, and check for "special requests" to change it:

special_requests = {
    "convert_upper": str.upper,
    "convert_lower": str.lower,
    "vanilla": str
}
func = str

while True:
    i = input("? ")
    if i in special_requests:
        func = special_requests[i]
    else:
        print(func(i))
? abc123
abc123
? convert_upper
? abc123
ABC123
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading