Python 2.7.3 memory error

Posted by Tom Baker on Stack Overflow See other posts from Stack Overflow or by Tom Baker
Published on 2012-11-29T20:53:15Z Indexed on 2012/11/30 5:04 UTC
Read the original article Hit count: 212

Filed under:

I have a specific case with python code. Every time I run the code, the RAM memory is increasing until it reaches 1.8 gb and crashes.

import itertools
import csv
import pokersleuth

cards = ['2s',  '3s',   '4s',   '5s',   '6s',   '7s',   '8s',   '9s',   'Ts',   'Js',   'Qs',   'Ks',   'As',   '2h',   '3h',   '4h',   '5h',   '6h',   '7h',   '8h',   '9h',   'Th',   'Jh',   'Qh',   'Kh',   'Ah',   '2c',   '3c',   '4c',   '5c',   '6c',   '7c',   '8c',   '9c',   'Tc',   'Jc',   'Qc',   'Kc',   'Ac',   '2d',   '3d',   '4d',   '5d',   '6d',   '7d',   '8d',   '9d',   'Td',   'Jd',   'Qd',   'Kd',   'Ad']
flop = itertools.combinations(cards,3)

a1 = 'Ks' ; a2 = 'Qs'
b1 = 'Jc' ; b2 = 'Jd'

cards1 = a1+a2
cards2 = b1+b2

number = 0
n=0
m=0

for row1 in flop:
    if (row1[0] <> a1 and row1[0] <>a2 and row1[0] <>b1 and row1[0] <>b2) and (row1[1] <> a1 and row1[1] <>a2 and row1[1] <>b1 and row1[1] <>b2) and (row1[2] <> a1 and row1[2] <> a2 and row1[2] <> b1 and row1[2] <> b2):
        for row2 in cards:
            if (row2 <> a1 and row2 <> a2 and row2 <> b1 and row2 <> b2 and row2 <> row1[0] and row2 <> row1[1] and row2 <> row1[2]):
                s = pokersleuth.compute_equity(row1[0]+row1[1]+row1[2]+row2, (cards1, cards2))
                if s[0]>=0.5:
                    number +=1
                    del s[:]
                del s[:]

        print number/45.0
        number = 0
        n+=1

© Stack Overflow or respective owner

Related posts about python