python双色球号码最大连开统计

q1:双色球红球33个里面任意选1个共33个,看哪个号最近连开的最久统计出来

双色球往期记录ssq.txt

=====================

2017093 7 7 9 15 22 27 12
2017092 7 7 19 29 32 33 9
2017091 5 5 10 23 28 29 3
2017090 1 7 10 16 22 33 9
2017089 11 12 13 16 23 25 12
2017088 5 5 18 22 23 29 6
2017087 7 7 13 14 19 28 6

=====================

2017093代表期数,后面代表数字

-------------------------------------------------

1、先每行读取每期记录并判断是否有重复数字,如果有就将对应的 日期、重复数据存放在dic字典里面

dic ={}#用于存放双色求每期出现重复号码

with open('C:\\ssq.txt') as file:   
    data = file.readlines()
    #print("*"*30)
    for nodes in data:
        node =nodes.split()
        print("node ===="+str(node))
        for i in node:
            if node.count(i)>1:
                lst =[]
                if i not in lst:
                    lst.append(i)
                    dic[node[0]] = lst                  
                else:
                    pass
            else:
                pass
print("dic ======="+str(dic))

2、然后拿出dic所有的value值,存放在一个列表中,然后列表遍历,找出有相同数字的号码

lst =[]#用于存放重复的号码
for  key  in dic:
    if dic[key]!=[]:
        lst.append(dic[key])
    else:
        pass
print("%%%lst%%=="+str(lst))

3、跟据往期出现相同数据的号码找出对应的key存放新列表中

for i in range(0,len(lst)-1):
    
    for j in range(i+1,len(lst)):
        cc =list((set(lst[i]).union(set(lst[j])))^(set(lst[i])^set(lst[j])))#判断往期重号是否有相同的数字
        if len(cc)>0:
            list11= []
            print("cc&&&&&&&&"+str(cc))
            #flg=True
            #while flg:
            #找出重复数字对于的日期
            for k,v in dic.items():
                #print("KKK=="+str(k))   
                #print("vvv=="+str(v))
                print("KKKKKKKKKKKKKKKKK") 
                print(type(k))                                      
                if v == cc:
                    print("&&KK&&"+str(k)+ " "+str(v))
                    list11.append(k)    
            print("list11==="+str(list11))

4、在新列表排序,相邻元素求差,并取出最小的差,将vlaue和最小差存放列表中

dic_mix =[]           
            list11.sort()#日期排序
            print("list11=XXXXX=="+str(list11))
            lkks=[]#用于存放list11.sort日期差
            for i in range(0,len(list11)-1):
                for j in range(i+1,i+2):           
                    dd = abs(int(list11[i])-int(list11[j]))
                    if dd not in lkks:#如果最小其数差不在列表中则添加
                        lkks.append(dd)
            kk =min(lkks)#找出最新的日期差
            dic_mix.append((cc,kk))
        else:
            pass
print("dic_mix =="+str(dic_mix))

输出

dic ======={'2017093': ['7'], '2017089': ['12'], '2017091': ['5'], '2017087': ['7'], '2017088': ['5'], '2017092': ['7']}
lst=======[['7'], ['12'], ['5'], ['7'], ['5'], ['7']]
dic_mix ==[(['7'], 1), (['5'], 3), (['7'], 1), (['7'], 1)]

 

posted on 2017-08-14 21:48  HZQ_HZA  阅读(581)  评论(0编辑  收藏  举报

导航