python - translate() function error -


the translate function giving me error i'm giving 2 members , should passing 1. correct code based on books i'm using currently. i'm using python 3.4.

import string fhand=open("c:\python34\leos code\mbox.txt") dictsort = dict() #decorate dictionary line in fhand:     line = line.translate(none, string.punctuation)     line = line.lower()     words = line.split()     word in words:         if word not in dictsort:             dictsort[word]= 1         else:             dictsort[word] += 1 #sort dictionary dictlst = [] k,v in dictsort.items():     dictlst.append((v,k)) dictlst.sort(reverse=true) k,v in dictlst[:10]:     print (k,v) 

a line of code should added , translate line modified:

remove_punctuation_map = dict((ord(char), none) char in string.punctuation) line = line.translate(remove_punctuation_map) 

there change in python 3.x tuple needs passed translate function, needs created in dictionary before , passed translate method.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -