Update: The requirement is “fixed length 9 digits” so 460 000 000 138 should be 460 000 138
I want to generate IDs on a special form such as 460 000 000 138 where 46 is the country code and the rest is the ID and this number always(?) has the same number of digits ie four pairs of threes.
My input is this ID that can be expected to be lower than some largest number. When starting the project from scratch the ID could be 1 and then just autoincrement as long as IDs don’t collide (I probably would want a sequential count but that is tricky in distributed environment where actions can happen at the same time.
So input could be for example 138. I now want to fill with zeros and the country number, in this case Sweden (46) so the output should be 460 000 000 138
Similarly, if input is 1138 the output should be on the same form an fill with less zeroes ie 460 000 001 138
So I don’t know how many zeroes I need. Can you help me? The solution should be in python. I will probably use the entity ID, fill with zeroes and add the country code and can you help me find an algorithm in python for that?
Any help is greatly appreciated
string.zfill()serves exactly this purpose.after that you just need to format the string to prepend the country code and then insert spaces wherever you require