coding utf-8 __author__ pilgrim team_looking_for Arsenal open Foot txt

 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
80
81
82
83
84
85
86
87
88
89
# -*- coding: utf-8 -*-
__author__ = 'pilgrim'
# team_looking_for = 'Arsenal'
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
# print list_of_next_game
# print '------------'
#считаю Х для всех команд для последней игры
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)}
# print 'team:', my_dict.keys(), 'X: ', my_dict.values()
list_of_x.append(my_dict)
# print list_of_x
# для команд, которые сыграют между собой тащу рассчитанный Х
for pair in list_of_next_game:
count = 0
for el in pair.split(' '):
count += 1
if count == 1 or count == 2:
for x in list_of_x:
if el == x.keys()[0]:
pair = pair + ' ' + str(x.values()[0])
if count % 2 == 0:
# print 'pair', pair
print 'pair', pair[-5:]
# print 'for me'
# print pair[-1]
# print pair[-2]
# print pair[-4]
# print pair[-5]
# if pair[-2] != '-' and pair[-5] != '-':
# delta_111 = int(pair[-4]) - int(pair[-1])
# if pair[-2] == '-' and pair[-5] == '-':
# delta_111 = 0 - (int(pair[-4]) + int(pair[-1]))
# if pair[-2] != '-' and pair[-5] == '-':
# print 'delta_111', delta_111
# print 'end for'