Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81720
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-11-29 11:35 -0800 |
| Message-ID | <7d92e814-9d27-4f7d-a189-49fa84e51a34@googlegroups.com> (permalink) |
| Subject | Help needed |
| From | Gautam R Bharadwaj <gautamrbharadwaj@gmail.com> |
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
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Help needed Gautam R Bharadwaj <gautamrbharadwaj@gmail.com> - 2014-11-29 11:35 -0800 Re: Help needed Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-30 12:28 +0000
csiph-web