Idea inspired (or stolen) by the 1BRC challenge, I've setup a 1-million-row-challenge for you to solve in Python.
Your task is to write a program that parses the measurements.txt file to calculate the minimum, maximum and average temperatures in each city.
Some example from measurements.txt:
Nässjö;89.1
Nässjö;12.6
Trollhättan;37.9
Trollhättan;33.4
Vänersborg;11.7
Your program should produce an output in this format:
Nässjö=12.6/50.8/89.1
Trollhättan=33.4/35,6/37.9
Vänersborg=11.7/11.7/11.7
Download the git repository to a local folder. If you have git installed, you can run the following command in your terminal (cmd.exe) to download and open the folder:
C:\Users\emieli> git clone https://github.com/emieli/t2-1mrc.git
Cloning into 't2-1mrc'...
[...]
Receiving objects: 100% (8/8), 7.40 MiB | 23.18 MiB/s, done.
C:\Users\emieli> code t2-1mrc
(OR)
C:\Users\emieli> explorer t2-1mrc
You now have a local copy of the GIT repository.
If you have VS-code installed then you can type code t2-1mrc in cmd to open the project.
If you don't have VS-code then you can type explorer t2-1mrc in cmd to open the directory in your file explorer.
You can now open t2-1mrc\main.py and start coding!
In case you get stuck, feel free to browse these resources for inspiration:
- https://www.geeksforgeeks.org/python/read-a-file-line-by-line-in-python/
- https://docs.python.org/3/tutorial/datastructures.html#dictionaries
- https://docs.python.org/3/tutorial/datastructures.html#looping-techniques
- https://docs.python.org/3/tutorial/controlflow.html (if-statements & for-loops)
If you get really stuck, You can find one way to solve the problem in the solution folder.