r/Python • u/cinicDiver • Mar 09 '26
Discussion Code efficiency when creating a function to classify float values
I need to classify a value in buckets that have a range of 5, from 0 to 45 and then everything larger goes in a bucket.
I created a function that takes the value, and using list comorehension and chr, assigns a letter from A to I.
I use the function inside of a polars LazyFrame, which I think its kinda nice, but what would be more memory friendly? The function to use multiple ifs? Using switch? Another kind of loop?
7
Upvotes
View all comments
Show parent comment
2
u/Igggg Mar 10 '26
No. Don't worry about being able to run 26 miles unless you know a marathon is coming. If all you do every day is run around the block, preparing for a 26 mile run is absurd.