input from the keyboard (standard input) containing the results of several tennis matches. Each match's score is recorded on a separate line with the following format:
Winner:Loser:Set-1-score,...,Set-k-score, where 2 <= k <= 5
For example, an input line of the form
The input is terminated by a blank line.
Python program that reads information about all the matches and compile the following statistics for each player:
Is this what you are after?
>>> d= >>> while(True): ... s=raw_input() ... if s=="":break ... temp = [s] ... d.append(temp) ... a,b,7-6,7-6,6-3 c,d,7-4,7-6,6-2 e,f,6-4,7-6,6-2 >>> d [['a,b,7-6,7-6,6-3'], ['c,d,7-4,7-6,6-2'], ['e,f,6-4,7-6,6-2']]
This makes a list item out of the input and then appends that list to your main list
You now should be able to process
If you persist in using 2 separators both
, you are making life more difficult for yourself, Stick with one!
Revising the simple code above:
d= while(True): s=raw_input() if s=="":break temp = [s] d.append(temp) #d becomes a list of lists for item in d: #process individual lists in d x=item.split(",") # break up the list using the separator comma for i in range(0,len(x)): #access each item in x print x[i]
Djokovic Murray 2-6 6-7 7-6 6-3 6-1 Bloggs Smith 2-6 6-7 7-6 6-3 6-3 Jones Abernathy 6-3 6-3 6-3