Python Forum
capitalize all letters
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
capitalize all letters
#1


hi. i have a text and i need to get all first letters/numbers of each word, capitalize and put a dot after each one.
the
text='''kldjsh sdfbdb dbsd 67 dshss'''
one=[x[0] for x in text.strip() ]
print(one)
with the above code i did manage to get the first letter of each word but i miss the upper case, the dot and a space after each word. some help please?
i tried
print(one.upper()) 
but it returns error.
Reply
#2
text = text.title()
Reply
#3
OK i got all the first letters in capital, but i have them in between apostrophes '. I would like them to be without apostrophe. eg if the letters are NHJUI4G then have them as in the following format: N. H. J. U. I. 4. G.
how do i fix that please?
Reply
#4
use str.join()
Reply
#5
(Dec-03-2017, 06:27 PM)buran Wrote: use str.join()
sorry i've lost you on how to use it in my program.
Reply
#6
>>> my_list = ['N', 'H', 'J', 'U', 'I', '4', 'G']
>>> '.'.join(my_list)
'N.H.J.U.I.4.G'
>>>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Capitalize first letter of names in nested loops student_of_python 9 4,695 Oct-27-2019, 07:51 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020