3) in python Copy the Plain Text UTF-8 version of Bram Sroker’s Dracula from the site: http://www.gutenberg.org/ebooks/345 into a text document called ‘dracula.txt’. Write python code that reads the text document and counts the unique words and stores the words and counts into a dictionary. Write the words and counts into a text file called ‘dracula words.txt’ by using the Python file handle method seen in class. Generate a list called ‘sorted counts’ that contains the value and key pairs as tuples that are sorted in descending order based on the frequencies of the words. For example, it should be in the form: [(7423, ‘the’), (5640, ‘and’), (4499, ‘I’), (4462, ‘to’), (3673, ‘of’), (2891, ‘a’), (2384, ‘in’), (ect.) Here, the word ‘the’ occurs the most frequently. Output the top 10 most frequently occurring words. How often does the word ‘Dracula’ come up in the entire Novel? Hint: use list comprehension. For the dictionary ‘counts’ the command ‘counts.items()’ returns an object of type dict items that contains the key value pairs in the form of tuples. You can iterate over these with the command: for (key, value) in counts.items(). Thus, you can get a list by finishing the following code: sorted_counts = [(value, key) for (key, value) in ??? ??? ]. You can now sort it element by element since tuples sort in a similar manner to other Python
3) in python
Copy the Plain Text UTF-8 version of Bram Sroker’s Dracula from the site:
http://www.gutenberg.org/ebooks/345 into a text document called ‘dracula.txt’. Write python
code that reads the text document and counts the unique words and stores the words and counts
into a dictionary. Write the words and counts into a text file called ‘dracula words.txt’ by using
the Python file handle method seen in class. Generate a list called ‘sorted counts’ that contains
the value and key pairs as tuples that are sorted in descending order based on the frequencies of
the words. For example, it should be in the form:
[(7423, ‘the’),
(5640, ‘and’),
(4499, ‘I’),
(4462, ‘to’),
(3673, ‘of’),
(2891, ‘a’),
(2384, ‘in’),
(ect.)
Here, the word ‘the’ occurs the most frequently. Output the top 10 most frequently occurring
words. How often does the word ‘Dracula’ come up in the entire Novel?
Hint: use list comprehension. For the dictionary ‘counts’ the command ‘counts.items()’ returns an
object of type dict items that contains the key value pairs in the form of tuples. You can iterate over
these with the command: for (key, value) in counts.items(). Thus, you can get a list by finishing the following code: sorted_counts = [(value, key) for (key, value) in ??? ??? ].
You can now sort it element by element since tuples sort in a similar manner to other Python
objects.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 2 images