Question: Write a program that reads in a filename provided by the user, opens it and reads all of the lines. Create a dictionary to hold
Write a program that reads in a filename provided by the user, opens it and reads all of the lines. Create a dictionary to hold the line numbers for each valid identifier found. Your solution will need to process each line to determine whether a valid identifier exists on that line and if so, record both the line number and identifier found in the dictionary.
A valid identifier must be a string consisting of only letters, numbers, and underscores. If a line contains an invalid identifier no record is made in the dictionary. If a line contains a valid identifier already recorded in the dictionary append the line number to the dictionary log of where the identifier was found.
Here are some other requirements:
1. Keep provided test file intact
2. Use t4.py as your input test file to generate submission run output
3. Verify identifiers are valid; ignore if invalid
----------------------------------------------------------------------------------------------------------------------------------------------
special characters such as "@", "!", and "." are considered invalid identifiers, underscores and numbers (can also start with such) are considered valid identifiers.
I have seen other examples but the use 'import re' I don't, however, know much about that library so if it could be done without using it, would be great!
the file I am using contains the following:
apple
1
1
ball
art
dog
&
pen
rat
4
apple
1@.
carrot
!
orange
ant
ant
ant
ball
stick
pen
_
$a
***
goodbye
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
