Indeed, my main loop did not run up until total/2.
Also, it assumed first != second, when printing the count of each occurrence.
Here's my new solution that adresses those issues.
Just like the first one, this code assumes that a is an
unordered list of positive integers.
#!/usr/bin/python
total = 10
a = [4,5,6,1,3,8,3,5,8,6]
d = {k: a.count(k) for k in set(a)}
for i in d.keys():
if i <= total/2 and d.has_key(total-i):
for first in range(d[i]):
d[i] -= 1
for second in range(d[total-i]):
d[total-i] -= 1
print (i, total-i)
output:
(4, 6)
(4, 6)
(5, 5)