Python Forum
capitalizing words in list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
capitalizing words in list
#1
# [ ] split the sentence, code_tip, into a words list
# [ ] print the joined words in the list with no spaces in-between
# [ ] Bonus: capitalize each word in the list before .join()
code_tip ="Read code aloud or explain the code step by step to a peer"

my code:
code_tip = "Work hard and believe in yourself."
wl = code_tip.split()
print(''.join(wl))
Don't know how to capitalize each word in the list before .join(). I tried with .str() but it gives error: AttributeError: 'list' object has no attribute 'str'
Reply
#2
>>> code_tip = "Work hard and believe in yourself."
>>> wl = code_tip.split()
>>> for n, x in enumerate(wl):
...     wl[n] = wl[n].capitalize()
>>> wl
['Work', 'Hard', 'And', 'Believe', 'In', 'Yourself.']
>>>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Duplicated words in a list pooyan89 7 9,186 Jun-15-2019, 08:21 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

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