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
.
├── LICENSE.md
├── README.md
├── requirements.txt
├── .gitignore
└── src/
├── rank_array.py
└── test_rank_array.py
- Python 3.9 or higher
- pip (Python package installer)
- Clone the repository:
git clone git@github.com:luismr/python-rank-the-array-script.git
cd python-rank-the-array-script- Create and activate a virtual environment:
python3 -m venv venv
source venv/bin/activatepython -m venv venv
.\venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtThe 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]To run the test suite:
pytest src/test_rank_array.py -vFor coverage report:
pytest src/test_rank_array.py --cov=src --cov-report=term-missing- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE.md file for details.