Question: pyhton Question II: Write a program that reads in a Python source code file and counts the occurrence of each identifier (variables, class, and method

pyhton
Question II: Write a program that reads in a Python source code file and counts the occurrence of each identifier (variables, class, and method names) in the file using a dictionary. Another dictionary is used to positions of identifiers with a list in the file. Your program should prompt the user to enter the Python source code filename and then construct these two dictionaries. After reading the entire file, the program should display the contents two dictionaries. Ex: ab = de # starts at 0 x= x + ab +1 #starts at 8 y = ab # starts at 22 dictCounts: {'ab': 3, 'de': 1, 'x': 3, 'y': 1} dictPositions: {'ab: [0, 16, 26], 'de': [5], 'x': [8, 12), 'y': [22]}
Step by Step Solution
There are 3 Steps involved in it
To solve this problem we need to create a Python script that processes a given Python source code file The script will count occurrences of each ident... View full answer
Get step-by-step solutions from verified subject matter experts
