Skip to content

luismr/python-rank-the-array-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Rank Array Script

Python 3.9

A Python script that ranks an array of scores according to specific rules:

  • Highest score gets rank 1
  • Second highest score gets rank 2
  • Tied scores receive the same rank
  • Ranks are returned in the same order as the input scores

Project Structure

.
├── LICENSE.md
├── README.md
├── requirements.txt
├── .gitignore
└── src/
    ├── rank_array.py
    └── test_rank_array.py

Prerequisites

  • Python 3.9 or higher
  • pip (Python package installer)

Installation

  1. Clone the repository:
git clone git@github.com:luismr/python-rank-the-array-script.git
cd python-rank-the-array-script
  1. Create and activate a virtual environment:

macOS/Linux

python3 -m venv venv
source venv/bin/activate

Windows

python -m venv venv
.\venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt

Usage

The script provides a function rank_array(scores) that takes a list of scores as input and returns a list of ranks.

Example:

from src.rank_array import rank_array

scores = [9, 3, 6, 10]
ranks = rank_array(scores)
print(ranks)  # Output: [2, 4, 3, 1]

Running Tests

To run the test suite:

pytest src/test_rank_array.py -v

For coverage report:

pytest src/test_rank_array.py --cov=src --cov-report=term-missing

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

Python script that ranks an array of scores according to specific rules

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages