Skip to content

Contender366/Sorting_Tool_Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Sorting Utility

A flexible command-line utility written in Python for sorting and analyzing different types of input data: numbers (longs), words, or lines. It supports sorting by natural order or by frequency count, with options to read from files or standard input and output to files or console.

Features

Supports three data types:

long: Parses and sorts integer numbers.

word: Extracts and sorts words.

line: Sorts whole lines of text.

Two sorting methods:

natural: Sorts data in ascending order.

byCount: Sorts data by occurrence frequency, then by value.

Flexible input:

Read from file or from standard input.

Flexible output:

Print to console or write to output file.

Robust error handling for invalid inputs and arguments.

Usage

Run the script with optional command-line arguments:

python main.py [-dataType TYPE] [-sortingType METHOD] [-inputFile FILE] [-outputFile FILE]

Arguments

-dataType TYPE Type of data to process. Accepted values: long, word, line Default: word

-sortingType METHOD Sorting method to use. Accepted values: natural, byCount Default: natural

-inputFile FILE Path to the input file. If omitted, reads from standard input.

-outputFile FILE Path to the output file. If omitted, output is printed to console.

Example

Sort numbers in natural order from a file and write to output file:

python main.py -dataType long -sortingType natural -inputFile data.txt -outputFile result.txt

Read words from standard input and sort by count, printing to console:

python main.py -dataType word -sortingType byCount

Error Handling

Invalid or missing arguments will trigger warnings and default values will be used.

Tokens that cannot be parsed (e.g., non-integer tokens in number sorting) are skipped with a warning.

All error and warning messages are printed to the console regardless of output file settings.

Code Structure

DataProcessor base class handles common data management.

NumberSorter, WordSorter, and LineSorter extend the base class for specific data processing.

Main program parses arguments, reads input, instantiates the appropriate processor, and outputs sorted results.

Requirements

Python 3.x

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages