GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Python_Sample_Programs/Find_a_word_1.py at main · sanathanan/Python_Sample_Programs Expand file tree/ Copy pathFind_a_word_1.pyMore file actions 24 lines (16 loc) · 641 Bytes / Copy pathFind_a_word_1.pyFile metadata and controls24 lines (16 loc) · 641 Bytes 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. |