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

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

1 Expert Approved Answer
Step: 1 Unlock

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

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!