Mini Program 3 - Pattern Matching in a text file

Hairbrow is stuck in her task. She has to search all occurrences of a word in a huge text file. As lazy to do a manual work, she approaches her buddy Knowddy for help. Then, they code not only to search words but also to highlight all occurrences and save the newly created output file.


Try to create your own python code from the pseudo code shared below. Here's the Knowddy's and Hairbrow's version of Python code (GitHub Link)

Visuals are created using canva

Comments

  1. Recently i was working on problem where I had to remove consecutive repetitive words
    I used following logic

    import re
    pattern = r'\b(?P\w+)(\s(?P=word))+'
    text = 'twinkle twinkle little star, the the the game has begun, please come here soon please '
    repl = r'\g'

    new_text = re.sub(pattern, repl, text)
    print(new_text)

    twinkle little star, the game has begun, please come here soon please

    ReplyDelete
    Replies
    1. repl= r'\gopen tag word close tag'
      some how tag is getting removed after publish, so have to write in words above

      Delete
    2. Thanks for sharing the code and information

      Delete
    3. That's awesome Shekhar. Thanks for sharing your experience with Python development.

      Delete

Post a Comment

Popular posts from this blog

Mini Program 14 - Health Insurance Data Analysis & Model building using Python - Part 1

Mini Program 15 - Health Insurance Data Analysis & Model building using Python - Part 2

Mini Program 16 - Health Insurance Data Analysis & Model building using Python - Part 3