Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.1 kB
3
Indexable
Never
def top5_words(text):
    x=text.split()
    empty={}
    emptylist=[]
    all_modes=[]
    
    #final=[]
    for i in (x):
        if i in empty:
            empty[i]=empty[i]+1
        else:
            empty[i]=1
    #return empty
    for tup in (empty.items()):
        emptylist.append((tup[1],tup[0]))
    g=sorted(emptylist,reverse=True)
    #return (g)
    print(g)
    for s in range(len(g)):
        #print(g[s][0])
        if(len(all_modes)==5): 
            break
        if g[s][0]==g[s+1][0]:
            comparing=[] 
            print(g[s][1])
            print(g[s+1][1])
            comparing.append(g[s][1])
            comparing.append(g[s+1][1])
            comparing.sort()
            print(comparing)
            all_modes.append(comparing)
            #return all_modes
        else:
            all_modes.append(g[s][1])
    return all_modes
            
    #return all_modes
            #comparing[]
            #for y in comparing:
                
            
            
        
        
        
    #return g
    #return y
    
    #for x in empty.items():
     #   y=sorted