From: steve <st...@lonetwin.net> > I am sorry, I didn't quite understand this bit "it is necessary to generate a > random list of 6 holes.", since the list below has 18 elements.
That means out of the 18 elements from the list, we need 6 random elements but with one constraint. > In any case, whether you need 6 or 18 -- the simplest way to do this would be: > > >>> l = [] > >>> for i in range(6): > ... l.append(random.choice([3,4,5])) random.choice([3,4,5]) may also possibly generate [3,3,4,3,4,3] (http://docs.python.org/library/random.html#random.choice), which violates our constraint. We need at least 1 occurrence of all the three elements. > ... > >>> l > [4, 5, 3, 4, 5, 5] > > # ...where the index is the hole number and the element is the par, or if you > # need it in the format you showed: > > >>> l = [] > >>> for i in range(1, 19): > ... l.append((i, random.choice([3,4,5]))) > ... > >>> l > [(1, 5), (2, 3), (3, 4), (4, 5), (5, 3), (6, 3), (7, 5), (8, 4), (9, 3), > (10, 5), (11, 5), (12, 5), (13, 4), (14, 5), (15, 3), (16, 5), (17, 3), (18, > 5)] > >>> You are getting it wrong. e.g there is no hole (4,5) in the sample data. Every hole has a fixed par type and we can't randomly associate one hole with a par type (as above). -- Gaurav Kalra Mobile: +91-9717-620-649 Facebook: /gauravkalra Twitter: @gvkalra _______________________________________________ BangPypers mailing list BangPypers@python.org http://mail.python.org/mailman/listinfo/bangpypers