python - what is the most pythoic way of indexing a file? -


(Warning: I am a newbie for Python language)

What will be the most dragon way

Here is an example text that I will use in my script.

It was the best time, it was the worst time, it was the age of intellect, it was the age of foolishness, it was an age of faith, it was an age of incredibility, it was the light of the season, it was It was the spring of hope, it was the spring of hope, it was winter of despair, we had everything with us, we had nothing, we were all going to heaven, we were all going on the other path-- In essence, this period was like the period so far, that its Some astute officers insisted on their getting, for good or evil, in the comparative level of comparative only.

The cola Season module is your friend for this question. I use a default word, I'll use words as keys in the text and the value will be the number of lines where the word has occurred. default defaults import d = defaultdict (list) for index, line enumerate (txt.splitlines ()): for word: word_strip = word.strip (',.!? 'D' [word_strip] .append (index)

I have assumed that the text is included in a variable txt, also that you get rid of various punctuation Want to

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -