Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Populate range when all I have is beginning and end

If I have the following:

ABC0001-ABC0004, what would be the most efficient to output ABC0001,ABC0002,ABC003,ABC0004?

I realize there is a range function in python but at first glance it only works with numbers.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thanks

I have tried Range but it only seems to work for numbers, I am not experienced enough to do much more than that and googling is only returning stuff related to range.

>Solution :

You can solve this by creating a range and adding that to a prefix string.
The result of range can also be zfiled.
Here is a small example of how you might generate those values into a list.

prefix = "ABC"

range = range(1, 10)

output = []
for i in range:
    number = str(i).zfill(4)
    output.append(prefix + number)

print(output)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading