Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

no of words in a string in python

def word_count(string):
    # Here we are removing the spaces from start and end,
    # and breaking every word whenever we encounter a space
    # and storing them in a list. The len of the list is the
    # total count of words.
    return(len(string.strip().split(" ")))

string="Python is an interpreted, high-level, general-purpose programming language"
print("'{}'".format(string),"has total words:",count_words(string))
string2=" Hi. My name is Ashwini "
print("'{}'".format(string2),"has total words:",word_count(string2))
Comment

PREVIOUS NEXT
Code Example
Python :: keras functional api embedding layer 
Python :: python enable pyqt errors 
Python :: python triangular number 
Python :: subprocess the system cannot find the file specifie 
Python :: python word encode asci 
Python :: how to display python output on html page django 
Python :: python clear memory 
Python :: python find cells with na 
Python :: iterating with index in for loops python 
Python :: User.objects.first() get specific id user in django 
Python :: RMSE value from cross validation 
Python :: add button to python gui file 
Python :: how to get checkbutton from a list 
Python :: how to check if a key is present in python dictionary 
Python :: numpy subtract 
Python :: how to import ui file in pyside 
Python :: python function 
Python :: python cointegration 
Python :: del df.loc 
Python :: python system performance 
Python :: pandas flip x and y axis 
Python :: gpu DBSCAN python 
Python :: lambda example python 
Python :: python zip 
Python :: seaborn set figure size 
Python :: numpy if zero is present 
Python :: read csv pandas nrow 
Python :: rolling std dev of a pandas series 
Python :: python dictionary delete based on value 
Python :: how to split strings in python 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =