Note that there are some explanatory texts on larger screens.

plurals
  1. POlookbehind in a for loop
    primarykey
    data
    text
    <p>How are you doing?</p> <p>Am kinda stuck with this problem, I need to use a for loop to find a word that ends with 'ing' and is preceded by a tag that is IN, I come from a background of C and java and there its easy to do, but I cant yet grasp how to do it in python!!</p> <p>I searched around and here is what I think i need to do:</p> <pre><code>for word, tag in list: if word.endswith('ing'): //use regular expression here which should look like this '(?&lt;=\bIN\b)ing' </code></pre> <p>now ofcourse there are some problems there, first I the I need to look at the previous tag not word, the regular expression is probably is wrong and more importantly this just sounds too complicated, am I missing something here, is there a way to just use the index of the word ending with 'ing' to look at the tag behind it like I would have done using java for example??</p> <p>Thank you in advance and sorry if its a silly question, its like my second time trying to write python and am still rusty with it =)</p> <p><em><strong>EDIT</em></strong>: more explanation on what I need to do, and an example here is what am trying to solve, sometimes pos_tag mistakes a VBG for a noun, so i need to write a method that given a tagged list (for example [('Cultivate', 'NNP'), ('peace', 'NN'), ('by', 'IN'), ('observing', 'NN'), ('justice', 'NN')] corrects this problem and returns [('Cultivate', 'NNP'), ('peace', 'NN'), ('by', 'IN'), ('observing', '<strong>VBG</strong>'), ('justice', 'NN')] ) notice how observing has changed </p> <p><em><strong>EDIT2</em></strong>: problem solved now, here is the solution def transform(li): for i in xrange(len(li)): if li[i][0].endswith('ing') and i > 0 and li[i-1][1]: li[i] = (li[i], 'VBG')</p> <p>thank you guys all for your help =D appreciated it </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload