[BangPypers] golf problem
Kenneth Gonsalves
lawgon at gmail.com
Wed Dec 28 13:00:45 CET 2011
On Wed, 2011-12-28 at 06:44 +0530, Kenneth Gonsalves wrote:
> def peoria(holes):
> import random
> random.shuffle(holes)
> result = []
> checklist = []
> used = []
> for hole in holes:
> if len(checklist) == 3:
> break
> if hole[1] not in checklist:
> result.append(hole)
> checklist.append(hole[1])
> used.append(hole)
> available = set(holes) - set(used)
> result.extend(list(available)[:3])
> return result
and the my final version:
def peoria(holes):
random.shuffle(holes)
result = []
checklist = []
for hole in holes:
if len(checklist) == 3:
break
if hole[1] not in checklist:
result.append(hole)
checklist.append(hole[1])
available = [x for x in holes if x not in result]
result.extend(available[:3])
return result
--
regards
Kenneth Gonsalves
More information about the BangPypers
mailing list