2
votes

I want to create a materialized path using python in like below sequence.

Expected seq.

0001, 0002, 0003, 0004, 0005, 0006, 0007, 0008, 0009, 000A, 000B, 000C, .... 000Z, 0010, 00011 and so on.

Basically, I have n number of elements in a list and I want to give a unique sequence number to every element in that list in the above manner.

mylist = [1,2,3,...n]
for i in mylist:
    # code to generate sequence number.

enter image description here

2

2 Answers

2
votes
import itertools

l = [str(x) for x in list(range(10))] + [chr(x) for x in range(65, 91)]

want = ["".join(x) for x in itertools.product(l, l, l, l)]
print(want[:10])
#['0000', '0001', '0002', '0003', '0004', '0005', '0006', '0007', '0008', '0009']
1
votes

try this for integer list

for i in my_list:
    print("{:04d}".format(i))

and this for all

for i in my_list:
    print(str(i).zfill(len(str(1000))))