import re
sums = dict()
fh= open(\'wordcount.txt\',\'r\')
for line in fh:
words = [word.lower() for word in re.findall(r\'\\b\\w+\\b\', line)]
for word in (w
Python 3 - method name and syntactical updates - nice collection of swizzles
1 - lambdas are throw-away anonymous functions mainly used with filter, map, reduce etc.
Here were are creating a function containing a print and key,value iteration.
f = lambda *x: None;
f( *( print( x,":",y ) for x,y in genre_counting.items() ) )
Games : 3862
Productivity : 178
Weather : 72
Shopping : 122
Reference : 64
Finance : 104
2 - repr() returns the canonical string representation of the object.
for x in genre_counting:
print(repr(x),":",genre_counting[x])
'Games' : 3862
'Productivity' : 178
'Weather' : 72
'Shopping' : 122
'Reference' : 64
'Finance' : 104
3 - %s is a string placeholder; %i is an integer placeholder
for k, v in genre_counting.items():
print( '%s : %i' % (k, v) )
Games : 3862
Productivity : 178
Weather : 72
Shopping : 122
Reference : 64
Finance : 104