Given a set of integers (e.g. {1000000, 20000000, 1234000, 1200000}
), I want to apply to all of them a function such that:
- the magnitude of a number is lowered as far as possible
- all numbers remain integers
- their relative proportions remain constant
In other words, I want to strip as many zeros as possible without losing any information other than absolute magnitude, so the set would become {1000, 20000, 1234, 1200}
Is there a term for this operation and is there an efficient Python function, or should I just quickly code this?
Edit: This solution is not a duplicate because it deals with singular numbers - in my case, the number of zeros depends on the particular set.
Edit 2: Green Cloak Guy provided a solution for my exact requirements, and Illmora one that does what I should have actually conceptualized in the first place.