fork download
  1. #with open "root_words.txt" as rfile, "affix_words.txt" as afile:
  2.  
  3. # use the 'with' line above instead of the two example data lines below
  4. rfile = ["read", "vote", "like"]
  5. afile = ["reading", "upvote", "unlikely"]
  6.  
  7. for rword, aword in zip(rfile, afile):
  8. try:
  9. rw_start = aword.index(rword)
  10. rw_end = rw_start + len(rword)
  11. result = " ".join( "E" if n==rw_start-1 else \
  12. "B" if n==rw_end else \
  13. "I" for (n, letter) in enumerate(aword) )
  14. except:
  15. result = "NOT FOUND!"
  16. print("root: '{}', affixed: '{}', stemmed: '{}'".format(rword, aword, result))
  17.  
Success #stdin #stdout 0.02s 9984KB
stdin
Standard input is empty
stdout
root: 'read', affixed: 'reading', stemmed: 'I I I I B I I'
root: 'vote', affixed: 'upvote', stemmed: 'I E I I I I'
root: 'like', affixed: 'unlikely', stemmed: 'I E I I I I B I'