Solve in PYTHON Code ONLY please!
Here is your code in Python :D
=======================================================================================
def organize(): fx = open("radishsurvey.txt", "r") # Open File data = fx.read().split("\n") # Make a list of entries by reading and then splitting by newline people_dict = {} # Initialization of 2 dictionaries radish_dict = {} for info in data: # For each entry item = info.split(",") # Split Person's Name and favourite Radish # So, item[0] is the person's Name and item[1] is his/her favourite radish item[0] = cleanword(item[0]) # Calling Clean Word Function to capitalize the words item[1] = cleanword(item[1]) people_dict[item[0]] = item[1] # Adding dictionary entries to the first dictionary if item[1] in radish_dict: # For second dictionary, if radish already present, increase its frequency radish_dict[item[1]] += 1 else: # Else, make new entry and initialize frequency to 1 radish_dict[item[1]] = 1 print(people_dict) # Print both of the dictionaries print(radish_dict) def cleanword(string): words = string.split(" ") # Separate the string by spaces newword = "" # Result clean string to be stored in a new word for word in words: newword += word.capitalize() + " " # Capitalize the word, and add space after it for next word(like surname) return newword.strip(" ") # Remove the last space organize()
======================================================================================
Here are the screenshots to make sure of the indentations
OUTPUT FOR THE GIVEN ABOVE RADISH TXT FILE
{'Mary Johnson': 'Black Raddish', 'Jimmy Buffet': 'Daikon Radish', 'Tommy Morris': 'French Breakfast Radish', 'George Jones': 'Horseradish', 'John Camp': 'Round Radish', 'Melissa Dark': 'Watermelon Radish', 'Kim Jordan': 'China Rose Radish', 'Alice Change': 'Early Scarlet Globe Radish', 'Stefanie Smith': 'German Giant Radish', 'Jeff Black': 'China Rose Radish', 'Jimmy Newman': 'Horseradish', 'Tammy George': 'Horseradish', 'Jianqing Liu': 'Horseradish'}
{'Black Raddish': 1, 'Daikon Radish': 1, 'French Breakfast Radish':
1, 'Horseradish': 4, 'Round Radish': 1, 'Watermelon Radish': 1,
'China Rose Radish': 2, 'Early Scarlet Globe Radish': 1, 'German
Giant Radish': 1}
If you have any queries, do drop a comment and I will surely respond :D. And if you liked the answer, do give an upvote :)
In-Class: Radishes Using the text file, radishsurvey.txt Write a script that will read the file, ...
C++ Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage. "FirstNames2015.txt" is a list of the most popular baby names in the United States and was provided by the Social Security Administration. Each line in the file contains a boy's name and a girl's name. The file is space-delimited, meaning that the space character is used to separate the boy name from the girl name....