Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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