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 _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers