- 1 (266.84 KiB) Viewed 31 times
CSEN1021-B08 / Files#06-Create-Cate... D Files Run main.py x : res 오오 main.py Submit places 1.txt 1 def category_dict(fi
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
CSEN1021-B08 / Files#06-Create-Cate... D Files Run main.py x : res 오오 main.py Submit places 1.txt 1 def category_dict(fi
CSEN1021-B08 / Files#06-Create-Cate... D Files Run main.py x : res 오오 main.py Submit places 1.txt 1 def category_dict(filename): 2. # Write your logic here 3 dictionary = {} 4. 5 return dictionary 6 Console Shell Instructions You will be given a text file like the below one E places2.txt Packager files 7 Visakhapatnam City Tanali Town Mumbai City Kodavatukallu Village Maavooru Village Anantapuram Town 8 if __name__ == "__main__": print(category_dict("places1.txt")) poetry.lock 9 10 Pyproject.tom! your task is to form a dictionary which looks like this { "City: [ 'Visakhapatnam', 'Mumbai'], 'Town': [ 'Tanali', Anantapuram' ], 'Village': [ 'Kodavatikallu', 'Maavooru']} Hint: 1. Read each line into a list ist 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 istvate Windows Go to Settings to activate Windows ? CPU RAM Storage Type here to search