Wednesday

python setdefault in indexing text file


indx={}
with open(filename) as f:
for n,line in enumerate(f):
for word in line.split():
indx.setdefault(word,[]).append(n)
#emit in alphabetical order
for word in sorted(indx):
print "%s:" % word
for n in indx[word]: print n,
print

more...

No comments:

imagemagic add text to image

rem different types of text annotations on existing images rem cyan yellow orange gold rem -gravity SouthWest rem draw text and anno...