3

Capitalising the first letter of a sentence using .capitalize() works fine. Except when the first word of the sentence is an acronym like 'IBM' or 'SIM', which get lowercased (except for the first letter). For example:

L = ["IBM", "announced", "the", "acquisition."]
L = [L[0].capitalize()] + L[1:]
L = " ".join(L)
print(L)

gives:

"Ibm announced the acquisition."

But I would like this:

"IBM announced the acquisition."

Is there a way to avoid this - e.g. by skipping acronyms - while still outputting capitalised sentences like below?

"IBM's CEO announced the acquisition."
"The IBM acquisition was announced."
twhale
  • 725
  • 2
  • 9
  • 25

1 Answers1

2

Just capitalize the first character of the first word:

L = ["IBM", "announced", "the", "acquisition."]
L[0] = L[0][0].upper() + L[0][1:] #Capitalizes first letter of first word
L = " ".join(L)

print(L)
>>>'IBM announced the acquisition.'
iacob
  • 20,084
  • 6
  • 92
  • 119