Hướng dẫn count repeated words in a string python - đếm số từ lặp lại trong chuỗi python

Viết mã python để tìm tần số của mỗi từ trong một chuỗi đã cho. Ví dụ:

Input :  str[] = "Apple Mango Orange Mango Guava Guava Mango" 
Output : frequency of Apple is : 1
         frequency of Mango is : 3
         frequency of Orange is : 1
         frequency of Guava is : 2

Input :  str = "Train Bus Bus Train Taxi Aeroplane Taxi Bus"
Output : frequency of Train is : 2
         frequency of Bus is : 3
         frequency of Taxi is : 2
         frequency of Aeroplane is : 1

Được đề xuất: Vui lòng thử cách tiếp cận của bạn trên {IDE} trước, trước khi chuyển sang giải pháp.{IDE} first, before moving on to the solution.

Cách tiếp cận 1 bằng danh sách (): & nbsp; 

1 Split the string into a list containing the words by using split function (i.e. string.split()) in python with delimiter space.

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']

2. Khởi tạo một danh sách trống mới. & NBSP; Initialize a new empty list. 

3. Bây giờ hãy nối từ vào danh sách mới từ chuỗi trước nếu từ đó không có trong danh sách mới. & NBSP; Now append the word to the new list from previous string if that word is not present in the new list. 

4. Lặp lại trong danh sách mới và sử dụng chức năng đếm (tức là chuỗi.count (Báo chí [Lặp lại])) để tìm tần số của từ ở mỗi lần lặp. Iterate over the new list and use count function (i.e. string.count(newstring[iteration])) to find the frequency of word at each iteration.

Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2

Implementation:

Python3

def freq(str

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0__
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2 str
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
4

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
6
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
8

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0__
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
1
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
2 str
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
4

Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
5
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
6
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
1
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
8
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
2
Frequency of apple is : 3
Frequency of mango is : 3
Frequency of orange is : 2
Frequency of guava is : 1
0

Frequency of apple is : 3
Frequency of mango is : 3
Frequency of orange is : 2
Frequency of guava is : 1
1
Frequency of apple is : 3
Frequency of mango is : 3
Frequency of orange is : 2
Frequency of guava is : 1
2

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0__
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
1
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
2
Frequency of apple is : 3
Frequency of mango is : 3
Frequency of orange is : 2
Frequency of guava is : 1
7
Frequency of apple is : 3
Frequency of mango is : 3
Frequency of orange is : 2
Frequency of guava is : 1
8
Frequency of apple is : 3
Frequency of mango is : 3
Frequency of orange is : 2
Frequency of guava is : 1
9
Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3
0
Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3
1
Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3
2

Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
5
Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3
4
Frequency of apple is : 3
Frequency of mango is : 3
Frequency of orange is : 2
Frequency of guava is : 1
8
Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3
6
Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3
7
Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3
8
Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3
0str
Frequency of  Apple : 1 
Frequency of  Mango : 3 
Frequency of  Orange : 1 
Frequency of  Guava : 2 
1

def

Frequency of  Apple : 1 
Frequency of  Mango : 3 
Frequency of  Orange : 1 
Frequency of  Guava : 2 
3

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0____8
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2.

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0freq(__8

Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
6 def3
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2def6def7

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0def9

Đầu ra

Frequency of apple is : 3
Frequency of mango is : 3
Frequency of orange is : 2
Frequency of guava is : 1

Cách tiếp cận 2 bằng Set (): & NBSP; 

  1. Chia chuỗi thành một danh sách chứa các từ bằng cách sử dụng hàm chia (tức là chuỗi.split ()) trong python với không gian phân cách. & Nbsp;
  2. Sử dụng phương thức SET () để xóa một bản sao và để đưa ra một tập hợp các từ duy nhất & nbsp;set() method to remove a duplicate and to give a set of unique words 
  3. Lặp qua chức năng đếm và sử dụng (tức là chuỗi.count (Báo chí [Lặp lại])) để tìm tần số của từ ở mỗi lần lặp. & Nbsp;

Implementation:

Python3

def freq(str

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0__
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2 str
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
4

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
6
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
8

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0__
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
1
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
2 str
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
4

Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
5
Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3
4
Frequency of apple is : 3
Frequency of mango is : 3
Frequency of orange is : 2
Frequency of guava is : 1
8):2):3
Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3
8):5

Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
5
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
6
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
1
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
8
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
2
Frequency of apple is : 3
Frequency of mango is : 3
Frequency of orange is : 2
Frequency of guava is : 1
0

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0____8
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2.

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0freq(str
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
09

Đầu ra

Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3

Cách tiếp cận 2 bằng Set (): & NBSP;

Python3

Chia chuỗi thành một danh sách chứa các từ bằng cách sử dụng hàm chia (tức là chuỗi.split ()) trong python với không gian phân cách. & Nbsp;

Sử dụng phương thức SET () để xóa một bản sao và để đưa ra một tập hợp các từ duy nhất & nbsp;

Lặp qua chức năng đếm và sử dụng (tức là chuỗi.count (Báo chí [Lặp lại])) để tìm tần số của từ ở mỗi lần lặp. & Nbsp;

____10freq(5

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2 strfreq(8

____10str0

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2 str2str3

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
44def7

Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
5
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
47
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
16
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
49

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0__ str6
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
2 str8

Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
6 ):7__12

Cách tiếp cận 3 (sử dụng từ điển):

def

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
11

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
64

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
0
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
6
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
14
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
15
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
16
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
17__12
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
20def7

Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
5
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
23
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
14
Frequency of apple is : 3
Frequency of mango is : 3
Frequency of orange is : 2
Frequency of guava is : 1
9def7
Frequency of  guava is : 1
Frequency of  orange is : 2
Frequency of  mango is : 3
Frequency of  apple is : 3
1__

____10

Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
6
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
23
Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
2
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
37

Note:
string_name.count(substring) is used to find no. of occurrence of 
substring in a given string.

For example:
CODE   : str='Apple Mango Apple'
         str.count('Apple')
         str2='Apple'
         str.count(str2)
OUTPUT : 2
         2
5
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
39
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
40
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
16

Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
50
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
2
Note:
string_name.split(separator) method is used to split the string 
by specified separator(delimiter) into the list.
If delimiter is not provided then white space is a separator. 

For example:
CODE   : str='This is my book'
         str.split()
OUTPUT : ['This', 'is', 'my', 'book']
52

Đầu ra

Frequency of  Apple : 1 
Frequency of  Mango : 3 
Frequency of  Orange : 1 
Frequency of  Guava : 2