0% found this document useful (0 votes)
11 views6 pages

Word Frequency Analysis in Python

The document contains a Python script that reads a text file and counts the frequency of each word in the content. It outputs the frequency of words as they are encountered and provides a sorted list of the ten most frequently appearing words. The final output displays the word counts in descending order, highlighting 'technology' and 'is' as the most frequent words.

Uploaded by

Bhagyashree
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views6 pages

Word Frequency Analysis in Python

The document contains a Python script that reads a text file and counts the frequency of each word in the content. It outputs the frequency of words as they are encountered and provides a sorted list of the ten most frequently appearing words. The final output displays the word counts in descending order, highlighting 'technology' and 'is' as the most frequent words.

Uploaded by

Bhagyashree
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import pprint

import itertools

message1=open(r'Downloads/[Link]')

message=[Link]()

[Link]()

print('the content in the file is:\n\n',message)

count={}

for character in [Link]():

[Link](character,0)

count[character]=count[character]+1

print('frequency of words appeared in the semetence')

[Link](count)

sortedcount=sorted([Link](),key=lambda x:x[1],reverse=True)

converttodict=dict(sortedcount)

print('sorted in descending order:\n\n',converttodict)

sliceddict=dict([Link]([Link](),10))

print('10 most frequently appered word in a paragraph:\n\n',sliceddict)

Output
the content in the file is:

Bluetooth technology is a high speed low powered wireless technology that is used to
trnsmit and recieve data serially.
frequency of words appeared in the semetence
{'Bluetooth': 1}
sorted in descending order:

{'Bluetooth': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1, 'technology': 1}
sorted in descending order:

{'Bluetooth': 1, 'technology': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1, 'is': 1, 'technology': 1}
sorted in descending order:

{'Bluetooth': 1, 'technology': 1, 'is': 1}


frequency of words appeared in the semetence
{'Bluetooth': 1, 'a': 1, 'is': 1, 'technology': 1}
sorted in descending order:

{'Bluetooth': 1, 'technology': 1, 'is': 1, 'a': 1}


frequency of words appeared in the semetence
{'Bluetooth': 1, 'a': 1, 'high': 1, 'is': 1, 'technology': 1}
sorted in descending order:

{'Bluetooth': 1, 'technology': 1, 'is': 1, 'a': 1, 'high': 1}


frequency of words appeared in the semetence
{'Bluetooth': 1, 'a': 1, 'high': 1, 'is': 1, 'speed': 1, 'technology': 1}
sorted in descending order:

{'Bluetooth': 1, 'technology': 1, 'is': 1, 'a': 1, 'high': 1, 'speed': 1}


frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'high': 1,
'is': 1,
'low': 1,
'speed': 1,
'technology': 1}
sorted in descending order:

{'Bluetooth': 1, 'technology': 1, 'is': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1}


frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'high': 1,
'is': 1,
'low': 1,
'powered': 1,
'speed': 1,
'technology': 1}
sorted in descending order:

{'Bluetooth': 1, 'technology': 1, 'is': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'high': 1,
'is': 1,
'low': 1,
'powered': 1,
'speed': 1,
'technology': 1,
'wireless': 1}
sorted in descending order:
{'Bluetooth': 1, 'technology': 1, 'is': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,
'powered': 1, 'wireless': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'high': 1,
'is': 1,
'low': 1,
'powered': 1,
'speed': 1,
'technology': 2,
'wireless': 1}
sorted in descending order:

{'technology': 2, 'Bluetooth': 1, 'is': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1, 'wireless': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'high': 1,
'is': 1,
'low': 1,
'powered': 1,
'speed': 1,
'technology': 2,
'that': 1,
'wireless': 1}
sorted in descending order:

{'technology': 2, 'Bluetooth': 1, 'is': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1, 'wireless': 1, 'that': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'high': 1,
'is': 2,
'low': 1,
'powered': 1,
'speed': 1,
'technology': 2,
'that': 1,
'wireless': 1}
sorted in descending order:

{'technology': 2, 'is': 2, 'Bluetooth': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1, 'wireless': 1, 'that': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'high': 1,
'is': 2,
'low': 1,
'powered': 1,
'speed': 1,
'technology': 2,
'that': 1,
'used': 1,
'wireless': 1}
sorted in descending order:

{'technology': 2, 'is': 2, 'Bluetooth': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1, 'wireless': 1, 'that': 1, 'used': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'high': 1,
'is': 2,
'low': 1,
'powered': 1,
'speed': 1,
'technology': 2,
'that': 1,
'to': 1,
'used': 1,
'wireless': 1}
sorted in descending order:

{'technology': 2, 'is': 2, 'Bluetooth': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1, 'wireless': 1, 'that': 1, 'used': 1, 'to': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'high': 1,
'is': 2,
'low': 1,
'powered': 1,
'speed': 1,
'technology': 2,
'that': 1,
'to': 1,
'trnsmit': 1,
'used': 1,
'wireless': 1}
sorted in descending order:

{'technology': 2, 'is': 2, 'Bluetooth': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1, 'wireless': 1, 'that': 1, 'used': 1, 'to': 1, 'trnsmit': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'and': 1,
'high': 1,
'is': 2,
'low': 1,
'powered': 1,
'speed': 1,
'technology': 2,
'that': 1,
'to': 1,
'trnsmit': 1,
'used': 1,
'wireless': 1}
sorted in descending order:

{'technology': 2, 'is': 2, 'Bluetooth': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1, 'wireless': 1, 'that': 1, 'used': 1, 'to': 1, 'trnsmit': 1, 'and': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'and': 1,
'high': 1,
'is': 2,
'low': 1,
'powered': 1,
'recieve': 1,
'speed': 1,
'technology': 2,
'that': 1,
'to': 1,
'trnsmit': 1,
'used': 1,
'wireless': 1}
sorted in descending order:

{'technology': 2, 'is': 2, 'Bluetooth': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1, 'wireless': 1, 'that': 1, 'used': 1, 'to': 1, 'trnsmit': 1, 'and': 1, '
recieve': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'and': 1,
'data': 1,
'high': 1,
'is': 2,
'low': 1,
'powered': 1,
'recieve': 1,
'speed': 1,
'technology': 2,
'that': 1,
'to': 1,
'trnsmit': 1,
'used': 1,
'wireless': 1}
sorted in descending order:

{'technology': 2, 'is': 2, 'Bluetooth': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1, 'wireless': 1, 'that': 1, 'used': 1, 'to': 1, 'trnsmit': 1, 'and': 1, '
recieve': 1, 'data': 1}
frequency of words appeared in the semetence
{'Bluetooth': 1,
'a': 1,
'and': 1,
'data': 1,
'high': 1,
'is': 2,
'low': 1,
'powered': 1,
'recieve': 1,
'serially.': 1,
'speed': 1,
'technology': 2,
'that': 1,
'to': 1,
'trnsmit': 1,
'used': 1,
'wireless': 1}
sorted in descending order:

{'technology': 2, 'is': 2, 'Bluetooth': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1, 'wireless': 1, 'that': 1, 'used': 1, 'to': 1, 'trnsmit': 1, 'and': 1, '
recieve': 1, 'data': 1, 'serially.': 1}
10 most frequently appered word in a paragraph:

{'technology': 2, 'is': 2, 'Bluetooth': 1, 'a': 1, 'high': 1, 'speed': 1, 'low': 1,


'powered': 1, 'wireless': 1, 'that': 1}
[ ]:

Click to add a cell.

You might also like