0

I am doing a python assessment in school which requires me to take an inputted sentence and a word the user inputs to analyse the text and output the positions of where the word is in the text, for part of this task i am trying to convert the inputted sentence into a list, but i am a bit stuck. any chance of some help?

  • 1
    Of course someone will help, but first you need to give us your code snippet, output and expected output. – acknowledge Oct 02 '16 at 11:55
  • 1
    `"Hello World of Python".split()` -> `["Hello", "World", "of", "Python"]` – furas Oct 02 '16 at 11:56
  • We are not here to do your homework for you, show what you've done, tell where you are stuck and what you expect. People will be more inclined to answer that way :) – solarc Oct 02 '16 at 12:12
  • @Louis, what is "the position" in your case? Index of a first letter of a word in a sentence string? Index of a word in a list of sentence's words? – skovorodkin Oct 02 '16 at 12:34

1 Answers1

0

Are you trying to make a list of the words in the sentence, or of each character? If the former; then as you did with string.split() is fine. If the later; try creating a list and then adding each character of the string to it. This is how I'd do it:

string="Hello World of Python"
char_list=[]
for char in string:
    char_list.append(char)
maze88
  • 850
  • 2
  • 9
  • 15