Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions submissions/chelzakaria/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import polars as pl
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it an external lib?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes ! Isn't allowed ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Only standard lib can be used

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright then. But it should be mentioned in the rules

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rules updated to reflect this



def fun():
df = pl.scan_csv("input.txt", new_columns=["City", "Product", "Price"])

cheapest_city = (
df.group_by("City")
.agg(pl.sum("Price").alias("Total_Price"))
.sort("Total_Price")
.select(["City", "Total_Price"])
.collect(streaming=True)
.head(1)
)

cheapest_city_df = df.filter(pl.col("City") == cheapest_city["City"][0])
result = (
cheapest_city_df.group_by("Product")
.agg(pl.min("Price").alias("Min_Price"))
.sort(["Min_Price", "Product"])
.select(["Product", "Min_Price"])
.limit(5)
.collect(streaming=True)
)

with open("output.txt", "w") as f:
cheapest_city.write_csv(f, has_header=False, separator=" ")
result.write_csv(f, has_header=False, separator=" ")


if __name__ == "__main__":
fun()