Python Forum
Trying to get the first letter of every word in a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to get the first letter of every word in a list
#1
I am trying to take out the first letter of every word in a list. It is not working. I believe the fault to be on line 9 but i can't figure out why.

def initialise(userText):
    lst = []
    firstLetters = []
    for i in userText:
        lst.append(i)
    firstLetters.append(lst[0])
    for x in lst:
        if x == " ":
            position = lst.index(x) + 1
            firstLetters.append(lst[position])
    userText = ''.join(firstLetters)
    return userText


text = input("Enter text: ")
print(initialise(text))
Reply


Messages In This Thread
Trying to get the first letter of every word in a list - by DanielCook - Jan-05-2021, 12:00 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  For Word, Count in List (Counts.Items()) new_coder_231013 6 2,497 Jul-21-2022, 02:51 PM
Last Post: new_coder_231013
  find some word in text list file and a bit change to them RolanRoll 3 1,482 Jun-27-2022, 01:36 AM
Last Post: RolanRoll
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,455 Aug-12-2021, 04:25 PM
Last Post: palladium
  Trying to find first 2 letter word in a list of words Oldman45 7 3,626 Aug-11-2020, 08:59 AM
Last Post: Oldman45
  Cant Append a word in a line to a list err "str obj has no attribute append Sutsro 2 2,523 Apr-22-2020, 01:01 PM
Last Post: deanhystad
  Python Speech recognition, word by word AceScottie 6 15,860 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  print a word after specific word search evilcode1 8 4,721 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  How do you replace a word after a match from a list of words in each line of a file? vijju56 1 3,415 Oct-17-2019, 03:04 PM
Last Post: baquerik
  returns index of list if contains a word zarize 0 1,799 Sep-09-2019, 09:29 AM
Last Post: zarize
  Score each word from list variable pythonias2019 6 3,297 Jun-13-2019, 05:44 PM
Last Post: gontajones

Forum Jump:

User Panel Messages

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