python 3.4.2

 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
__author__ = 'alexta'
def sort(a, sample):
k = 1
key_left = key_right = 0
while k < len(a):
for i in range(k):
if (a[i] == sample):
key_left += 1
for j in range(k, len(a)):
if (a[j] != sample):
key_right += 1
if (key_left == key_right):
return k
key_left = key_right = 0
k += 1
return -1
def main():
sample = 5
a = [5, 5, 1, 7, 2, 3, 5]
try:
print(sort(a, sample))
except ValueError:
return -1
if __name__ == '__main__':
main()