Help needed

Gautam R Bharadwaj gautamrbharadwaj at gmail.com
Sat Nov 29 14:35:18 EST 2014


Here is the code in python, this code arranges the alphabets in descending order and now I want to encode each alphabet with 0 and next alphabet with 1, then 00,01,10,11,000,001 and so on. Please help me with that.

//////////////////////////////////////////////////////////
//////////////////CODE////////////////////////

from collections import defaultdict
import string
text ='intalks is an organization comprised of passionate students'.lower().translate(None,string.punctuation+' ')
c = defaultdict(int)
c.update({letter:0 for letter in string.lowercase[:26]}) 
for letter in text:
        c[letter] += 1


for letter,freq in sorted(c.iteritems(),key=lambda (l,f): (-f,l)): 
        print freq, letter
        



More information about the Python-list mailing list