Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the
Task 1: Write a Python program that takes as input from the user the name of a file containing postcode/location information. Each line in the file consists of the postcode followed by a tab followed by a comma-separated list of locations that have that postcode. For example, the file postcode.txt contains: LE1 LE2 LE3 LE4 LE5 Leicester Oadby,Knighton,Highfields, Aylestone Braunstone, Glenfield, Groby Road Beaumont Leys, Belgrave,Birstall, Thurmaston Hamilton, Thurnby Lodge, Evington Your program should create a list of postcode/location pairs with each pair stored in the list. It should print the list, so that you can check that your program has performed correctly. Please enter the file name: postcode.txt [['LET', ['Leicester']], ['LE2', ['Oadby', 'Knighton', 'Highfields', 'Aylestone']], ['LE3', ['Braunstone', 'Glenfield', 'Groby Road']], ['LE4', ['Beaumont Leys', 'Belgrave', 'Birstall', 'Thurmaston']], ['LE5', ['Hamilton', 'Thurnby Lodge', 'Evington']]] Note: You will need to use split twice: first to separate the postcode from the rest of the string and secondly to separate the rest of the strings into individual locations
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started