I am new to Python.. I want to know how can be the number of lines can be reduced? My task is to print whatever Simon says from the text file given below. the o/p should be sing,dance, go to school.
Is there any way to make the following program (xxxx.py) file in a single line of code?
simonfile.txt
I say: Play Cricket
Simon Says: Sing
Simon Says: Dance
Simon Says: Go to School
I say: Dance
xxx.py file
import sys
p = open('simonfile.txt')
for i in p.readlines():
s=i.split(':')
if ( s[0]=="Simon Says"):
print " S[0] " ,s[0]