samedi 5 juillet 2014

How can I get the list containing number of days having good sex?


Vote count:

0




The text file contains:



day 1 good study
day 2 good lunch
day 3 good sex
day 4 good dinner
day 5 good travel
day 6 good laugh
day 7 good sex


How can I get the list containing number of days having good sex?


My attempt is:



with open ('a.txt','r') as fi:
lines = fi.read().splitlines()
for line in lines:
if 'good sex' in line:
days = [int(line.split(' ')[1].split(' ')[0])]


print days


It produces only [7] as the result. But expected result is [3,7]. How is the good way of doing it?



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire