I have asked a question before about this bit of code and it was answered adequately, but I have an additional question about showing the ten most overdue numbers. (This program was a part of an in-class activity, I have already received full marks for what we have done. The question I am posting here was originally going to be done in-class but we ran out of time in lecture.)
#PE 8
#11-2-17def main():#import datawinninglist=get_data()#find frequency for lotterynumber 1-69frequency=find_frequency(winninglist)#sort the frequencysortedlist=sorting(frequency)print("The 10 most common numbers and their corresponding frequencies are: ")print(sortedlist[:10])print("The 10 least common numbers and their corresponding frequencies are: ")print(sortedlist[-10:])#find the 10 most overdue numbers#find the frequency of 1-69 for the regular numbers, and 1-26 for powerballdef get_data():#read from the fileinfile=open('power.txt','r')lines=infile.readlines()infile.close()#initialize winninglistwinninglist=[]#processraw data line by line, taking away new character lines, split using space, add to winninglistfor i in range(len(lines)):lines[i]=lines[i].rstrip('\n')item=lines[i].split()winninglist+=itemreturn winninglistdef find_frequency(winninglist):#frequency should be a listfrequency=[0]*69#count the occurance of each numberfor i in range(69):for item in winninglist:if int(item)==(i+1):frequency[i]+=1#print(frequency)return frequencydef sorting(frequency):#record both the number and frequencypb_frequency=[]for i in range(len(frequency)):pb_frequency.append([i+1, frequency[i]])#print(pb_frequency)#now sort using bubble sortingfor i in range(len(pb_frequency)):max=ifor j in range(i+1, (len(pb_frequency))):if pb_frequency[j][1]>pb_frequency[max][1]:max=j#max has the index of the highest frequency number for this round#we make the exchange to bubble the largest onetemp1=pb_frequency[i][0]temp2=pb_frequency[i][1]pb_frequency[i][0]=pb_frequency[max][0]pb_frequency[i][1]=pb_frequency[max][1]pb_frequency[max][0]=temp1pb_frequency[max][1]=temp2#print(pb_frequency)return pb_frequencymain()
Here is the format of the txt file:
17 22 36 37 52 24
14 22 52 54 59 04
05 08 29 37 38 24
10 14 30 40 51 01 (the txt file has many lines of numbers like these)
I need help showing the 10 most overdue numbers. Each line has an implied date attached to it, the first line being the oldest, so, I would need code to show the 10 numbers that have occurred least recently. Is there a simple solution that I am just not seeing?
For reference, here is my last question and answer
Can you help me fix code to show the occurrence of items in a list, for only the first five items?