Number Frequency and Sequence Analyzer (Enhanced)
This Python script analyzes a list of integers and reports:
- The most frequently occurring number (choosing the smallest in case of ties)
- The longest consecutive repetition of the same number (the value and its length)
- Runtime and peak memory usage
This is an enhanced version of the original script with improvements in structure, flexibility, and performance reporting.
Enhancements Included:
- Modular structure using if name == "main"
- Accepts both direct input and file-based input
- Tracks and prints:
- Total runtime in seconds
- Peak memory usage in megabytes
- Handles edge cases like:
- Empty input
- Non-integer values
- Suitable for large datasets
How to Use:
-
Run the analyzer python frequency_and_sequence_enhanced.py
You can then either:
- Enter a space-separated list of integers (e.g. 5 3 3 2 2 2 1)
- Or enter the path to a file containing the numbers (e.g. large_input.txt)
-
(Optional) Generate large test data Run the file generator: python generate_test_file.py
This will create 'large_input.txt' with 1,000,000 random numbers (range: 1–100)
To customize: Edit generate_test_file.py to change filename, count, or value range
Sample Output:
The smallest frequently occurring number is 2 and its frequency is 5 The longest same-number sequence is of number 3 and its length is 3 Time taken: 0.000128 seconds Peak memory usage: 0.0010 MB
Files:
- frequency_and_sequence_enhanced.py : main script
- generate_test_file.py : large input generator
- README.md : this documentation
Requirements:
- Python 3.6 or later
- No external packages required
Possible Future Extensions:
- Streaming-based version using generators
- CLI arguments instead of input prompts
- Export results to file (CSV, JSON)