Ok, I'm trying to figure out how to make a inputed phrase such as this in python ....
Self contained underwater breathing apparatus
output this...
SCUBA
Which would be the first letter of each word. Is this something to do with index? and maybe a .upper function?
Capitalization (American English) or capitalisation (British English) is writing a word with its first letter as a capital letter (uppercase letter) and the remaining letters in lower case, in writing systems with a case distinction.
To capitalize a word is to make its first letter a capital letter—an uppercase letter. For example, to capitalize the word polish (which is here spelled with a lowercase p), you would write it as Polish. A word whose first letter is a capital can be described as capitalized.
This is the pythonic way to do it:
output = "".join(item[0].upper() for item in input.split())
# SCUBA
There you go. Short and easy to understand.
LE: If you have other delimiters than space, you can split by words, like this:
import re
input = "self-contained underwater breathing apparatus"
output = "".join(item[0].upper() for item in re.findall("\w+", input))
# SCUBA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With