I am a newbie to Python and am playing with a sample lotto drawing software. I have gotten as far as creating a dictionary of results, from which my code chooses a set of numbers which come most often, least often, or three suggestions with a randomized mix of both. Now, I am interested in making my software learn to make better choices based on real results of lotto draw. I would also need to add those results to my dictionary. Any ideas?
My aim is not to become a millionaire (although that would be fun) only to see how such a learning code can be approached. Thank you for your time. Here is the code I have:
from random import choice
# Data created on 06.12.2013
LottoNumbers = {'1':336,'2':339,'3':383,'4':346,'5':369,'6':347,'7':364,'8':329,
'9':342,'10':345,'11':344,'12':336,'13':340,'14':330,'15':345,
'16':370,'17':376,'18':334,'19':343,'20':353,'21':334,'22':329,
'23':349,'24':351,'25':359,'26':378,'27':357,'28':347,'29':347,
'30':352,'31':365,'32':354,'33':310,'34':343,'35':341,'36':362,
'37':356,'38':361,'39':389,'40':351,'41':344,'42':385,'43':399,
'44':378,'45':357}
# Copy of Lotto Numbers in order not to accidentally damage or change it
LNC = LottoNumbers
#get a list of tuples, with value in 1st position, key second
li = [(value, key) for key, value in LNC.items()]
#sort the list
li.sort()
# needed number of items
m = 6
# grab the m highest values, from the end of the list
li_high_keys = [k for v, k in li[-m:]]
# grab the m lowest values from the beginning of the list
li_low_keys = [k for v, k in li[0:m]]
# add two lists together:
mixed_list = li_high_keys + li_low_keys
# create a list with 6 random items:
def ranList(list):
ranList = []
for i in range(0, 6):
item = choice(list)
if item in ranList:
item = choice(list)
ranList.append(item)
return ranList
# Get random choice from both lists:
ranList1 = sorted(ranList(mixed_list))
ranList2 = sorted(ranList(mixed_list))
ranList3 = sorted(ranList(mixed_list))
print "Numbers with highest frequency: "
print ', '.join(str(p) for p in li_high_keys)
print "Numbers with lowest frequency: "
print ', '.join(str(p) for p in li_low_keys)
print "Random mix of both lists: "
print ', '.join(str(p) for p in ranList1)
print ', '.join(str(p) for p in ranList2)
print ', '.join(str(p) for p in ranList3)
LNCwill also modifyLottoNumbers, it's just a reference to the same object not a copy!