In this post I will show you how to use the split function in python.

 

Open a python editor – as usual I will use IDLE – and type following. The program is self-explanatory.

 

import sys

MySent = sys.stdin.readline()   # read your input sentence

MyList = MySent.split(” “)  # split your sentence into a list (by every space)

print (MyList[3]) # print the fourth item oh your list

 

Now click Run -> Run Module         or       F5

 

The program will wait for your response.

Type a sentence then hit Enter and see the output.

 

Splitting a Sentence to a List

Leave a Reply

Your email address will not be published. Required fields are marked *