Files main.py x Submit E 1 def category_dict(filename): 2. # Write your logic here 3 dictionary = {} Console Shell Instr
Posted: Fri May 20, 2022 10:52 am
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