write a code and I can't seem to get it. I'm not sure if I'm making a
Question:
write a code and I can't seem to get it. I'm not sure if I'm making a minor error or what I'm doing wrong. How can it be written to produce the correct output?
Write a program that first reads in the name of an input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words and their frequencies (the number of times each word appears in the file) without any duplicates.
Ex: If the input is:
input1.csv
and the contents of input1.csv are:
hello,cat,man,hey,dog,boy,Hello,man,cat,woman,dog,Cat,hey,boy
the output is:
hello 1 cat 2 man 2 hey 2 dog 2 boy 2 Hello 1 woman 1 Cat 1
Note: There is a newline at the end of the output, and input1.csv is available to download.
import csv
# Use the input() function to get the variable "file_name"
# Create a variable "word_list" of type list
with open(str(file_name), 'r') as csvfile:
# Use the csv.reader(...,...) function to get the "user_file" handle
for row in user_file:
for index in range(len(row)):
if row[index] not in word_list:
# Use the print(...format(..., row.count(...))) functions
# to display the contents of the file to the console
word_list.append(row[index])
Business Communication Essentials a skill based approach
ISBN: 978-0132971324
6th edition
Authors: Courtland L. Bovee, John V. Thill