GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Python_Sample_Programs/Find_a_word_1.py at main · sanathanan/Python_Sample_Programs

Expand file tree

/

Find_a_word_1.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
24 lines (16 loc) · 641 Bytes
/

Find_a_word_1.py

Copy path

File metadata and controls

24 lines (16 loc) · 641 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Importing the Regex library for removing the unwanted character
import re
def word_count(input_str,word):
# removing ( ), - , ' , , , .
pre_processed_text = re.sub(pattern="[^\w\s]", repl=" ", string=input_str)
# Splitting the text
text_1 = pre_processed_text.split(" ")
count=0
for i in range(0, len(text_1)):
if word == text_1[i]:
count = count+1
return count
input_str = "foo bar (foo) bar foo-bar foo_bar foo'bar bar-foo bar, foo."
word = "foo"
count_words = word_count(input_str, word)
print("The total number of {} present is".format(word), count_words)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.