разница мячей в футбольных матчах

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# -*- coding: utf-8 -*-
__author__ = 'pilgrim'
f = open('Foot.1.txt', 'r')
content = f.readlines()
content.reverse()
#Собираю все команды в 1 массив
list_of_teams = list()
for string in content:
for team in string.split(' '):
if team.isalpha() and team not in list_of_teams:
list_of_teams.append(team)
# читаю последнюю игру
count = 0
list_of_next_game = list()
for current_str in content:
count += 1
if count < len(list_of_teams)/2 + 2:
list_of_next_game.append(current_str)
else:
break
#считаю Х для всех команд для последней игры
list_of_x = list()
for team_looking_for in list_of_teams:
num_of_entries = 0
last_team_delta = list()
for current_string in content:
if team_looking_for in current_string:
num_of_entries += 1
if num_of_entries > 1:
word_number = 0
score_1 = 0
score_2 = 0
for element in current_string.split(' '):
word_number += 1
if word_number == 3: # кол-во голов хозяина
score_1 = int(element)
if word_number == 4: # кол-во голов гостей
score_2 = int(element)
if current_string.startswith(team_looking_for):
delta = score_1 - score_2
else:
delta = score_2 - score_1
last_team_delta.append(delta)
if num_of_entries == 6:
break
summa_delt = 0
for score in last_team_delta:
summa_delt += score
my_dict = {team_looking_for: int(summa_delt)}
list_of_x.append(my_dict) # список Х для каждой команды
# сопоставляю Х каждой паре команд, играющей в следующем туре
# Х = Х_1 - Х_2
count = 0
home_team = []
guest_team = []
for string in list_of_next_game:
for word in string.split(' '):
if len(word) > 2: # считаю, что если длина слова в строке больше 2 символов, то это название команды
count += 1
if count % 2 != 0:
home_team.append(word)
else:
guest_team.append(word)
pairs = map(None, home_team, guest_team)
x_for_team = []
x_for_pair = []
for i in list_of_x: x_for_team.append(i.values()[0])
for i in range(0, len(x_for_team), 2): x_for_pair.append(x_for_team[i] - x_for_team[i+1])
pairs_with_x = map(None, pairs, x_for_pair)
for i in pairs_with_x: print i