Files main.py x Submit E 1 def category_dict(filename): 2. # Write your logic here 3 dictionary = {} Console Shell Instr

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Files main.py x Submit E 1 def category_dict(filename): 2. # Write your logic here 3 dictionary = {} Console Shell Instr

Post by answerhappygod »

Files Main Py X Submit E 1 Def Category Dict Filename 2 Write Your Logic Here 3 Dictionary Console Shell Instr 1
Files Main Py X Submit E 1 Def Category Dict Filename 2 Write Your Logic Here 3 Dictionary Console Shell Instr 1 (183.88 KiB) Viewed 47 times
it should passes the test cases
Files main.py x Submit E 1 def category_dict(filename): 2. # Write your logic here 3 dictionary = {} Console Shell Instructions You will be given a text file like the below one main.py places 1.txt 4 places 2.txt 5 return dictionary 6 Visakhapatnam City Tanali Town Mumbai City Kodavatikallu Village Maavooru Village Anantapuram Town Packager files 7 8 if -_name__="__main__": 9 print(category_dict("places1.txt")) 10 poetry.lock pyproject.toml your task is to form a dictionary which looks like this {'City': [ 'Visakhapatnam', Mumbai'], 'Town': [ 'Tanali', "Anantapuram'], "Village': [ 'Kodavatikallu', 'Maavooru']} Hint: I 1. Read each line into a list lst as strings 2. Next split ith index string in list ist into a templst where you will visualize them as two seperate strings as shown below ['Visakhapatnam', 'City'] 3. Take the second term as key and first term as values 4. As key cannot be duplicated check if the key is already there or not. I there append the found value or create a new key 5. Repeate the steps 2-4 until the len of list istivate Windows Go to Settings to activate Windows TV CPU RAM Storage w BI O Type here to search 33°C Mostly sunny g A gdx NG 15:45 17-05-2022
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply