M
mwdsmith
Hi, I'm new to python, and I'm not sure if this is the place to post
this kind of question; so feel free to tell me if I should take this
elsewhere.
So, to start me off on python, I decided to put together a little
script to test the probabilities of rolling certain combinations of
dice. Below is my code for checking for a full house (when rolling
with 5 dice). A roll is a list, eg [1, 3, 5, 1, 4] (this example is
not a full house)
def removeAll(element, num2Rem, list):
l = list[:]
for num in range(0, num2Rem):
l.remove(element)
return l
def isfullHouse(roll):
for die in range(1,7):
if roll.count(die)==3:
l = removeAll(die, 3, roll)
if l[0]==l[1]:
return 1
return 0
My questions is this: is there a better way to do this? A way that's
more natural to python, or just more efficient perhaps?
ps. A roll of [1, 2, 1, 1, 2] is a full house (three of one kind and
two of another)
this kind of question; so feel free to tell me if I should take this
elsewhere.
So, to start me off on python, I decided to put together a little
script to test the probabilities of rolling certain combinations of
dice. Below is my code for checking for a full house (when rolling
with 5 dice). A roll is a list, eg [1, 3, 5, 1, 4] (this example is
not a full house)
def removeAll(element, num2Rem, list):
l = list[:]
for num in range(0, num2Rem):
l.remove(element)
return l
def isfullHouse(roll):
for die in range(1,7):
if roll.count(die)==3:
l = removeAll(die, 3, roll)
if l[0]==l[1]:
return 1
return 0
My questions is this: is there a better way to do this? A way that's
more natural to python, or just more efficient perhaps?
ps. A roll of [1, 2, 1, 1, 2] is a full house (three of one kind and
two of another)