Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python, PART A: I am trying to get a dictionary with size(4, 5, 6) as keys and an array for key containing a list

In python,

PART A: I am trying to get a dictionary with size(4, 5, 6) as keys and an array for key containing a list of values (words from file of respective size) associated with those keys

I am reading from a file of strings, where I am only interested with words of length 4, 5, and 6 to compute my program reading the text file line by line:

At first, I have an empty dictionary then to that I want to add values to my arrays based on their respective size of strings

words_dictionary = open('file') word_list = dict([(4, []), (5, []), (6, [])]) print("Dictionary empty at initialization") print(word_list) def main(): lines = words_dictionary.readline().strip() count = 1
 for line in words_dictionary:  //I want to use a for loop, but I don't know how to go about that word_length = len(lines) if (word_length >= 4) and (word_length <= 6): lines = words_dictionary.readline().strip() words_dictionary[0] = words_dictionary[line[0]].append(line[1]) //Here is where I am trying to add values to the arrays words_dictionary[1] = words_dictionary[line[0]].append(line[1]) words_dictionary[2] = words_dictionary[line[0]].append(line[1]) print("Line {}: {} {} ".format(count, words_dictionary, word_length)) lines = words_dictionary.readline().strip() count += 1

main()

input file: { backspace, scan, power, vegan,delete, hope, meeting, limits, videos, phone, love, envy}

Example output:

4: [love, hope, scan, envy]

5 : [phone , power, vegan]

6:[delete, limits, videos]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions