This program reads the (UK) National Lottery Thunderball csv file available from their website and shows the most popular main ball numbers (between 1 and 39) and Thunderball numbers (1 to 14).
Note that the csv file is hard coded and should be changed depending on the csv file used. It works on the basis that the fields are : date, ball 1, ball 2, ball 3, ball 4, ball 5, Thunderball. If the field order / position changes, the program would need to be updated accordingly.
numbers=[] thunderball=[] # List of dictionaries for each set of numbers for x in range(0,40): # 1 - 39, we will ignore element 0 numbers.append({'no':x, 'count':0}) for x in range(0,15): # 1 - 14, we will ignore element 0 thunderball.append({'no':x, 'count':0}) try: myfile=open("thunderball.csv") except: print("Could not open the file...") exit() # Add numbers to our lists skip=True for line in myfile: # Skip first header line if skip==True: skip=False continue line=line.strip() if len(line)>0: fields=line.split(",") # Main numbers for c in range(1,6): numbers[int(fields[c])]['count']+=1 # Thunderball numbers thunderball[int(fields[6])]['count']+=1 myfile.close() # Sort so the most popular are at the top numbers.sort(key=lambda d: d['count'], reverse=True) thunderball.sort(key=lambda d: d['count'], reverse=True) # Display everything print("Popular Thunderball Numbers") print("===========================") print("Top 5 Main Ball's") print("-----------------") c=0 for text in numbers: print(str(text['no'])+"\tx"+str(text['count'])) c=c+1 if c==5: break c=0 print() print("Top 5 Thunderball's") print("-------------------") for text in thunderball: print(str(text['no'])+"\tx"+str(text['count'])) c=c+1 if c==5: break
Save the above as something, lottery.py for example, then run it as usual e.g:
#skip>py lottery.py Popular Thunderball Numbers =========================== Top 5 Main Ball's ----------------- 5 x23 1 x22 28 x21 25 x20 30 x18 Top 5 Thunderball's ------------------- 3 x11 5 x10 6 x9 9 x9 11 x9
Created 19/07/2025