How Python assigns values to empty characters in the list, each string is incremented by more than one retrieved value as a cardinality

there was a document before, in which I have to add the values automatically, but the values in it are unordered. Whenever I encounter an element with an empty value, I have to find the last value up and increase it. And cycle several times to count how many empty values there are in the middle

after I have processed it, the document has been able to automatically judge the new dict.keys after being added, but I have never been able to complete the logic and method of self-increment

related codes

def do_str_2():
    dict1 = []
    dict2 = []
    count = 0
    with open(sys.path[0]+"/success.txt","r") as f:
        for f in f.readlines():
            if "=" in f:
                f = f.replace("\n","").replace(",","").split("=")
                f[0] = f[0].strip()
                f[1] = f[1].strip()
                -sharp print(f)
                result_dict[f[0]] = f[1]
            else:
                f = f.replace("\n","").split(",")
                if len(f) > 1:
                    f[0] = f[0].strip()
                    f[1] = f[1].strip()
                    -sharp print(f)
                    result_dict[f[0]] = f[1]

    for value in result_dict.values():
        dict1.append(value)
    print(dict1)
    
  

the result of the final processing is a list of the values of the dictionary

["00", "01", "", "", "100000", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "10100", "10200", "200000", "", "", "", "", "", "20100", "20200", "1", "", "", "", "100", "101", "102", "103", "111", "112", "114", "115", "120", "121", "123", "124", "199", "10000", "10002", "10003", "10100", "10102"]

my final result is the same as the following list, but the value in it is added according to the last last non-empty value,
for example, ["00","01","",""] so now there are two empty elements that should find the value 01 as the cardinality to cycle
twice, and the result is ["00,"01,"02,"03], asking for the big answer

.
["00", "01", "02", "03", "100000", "100001", "100002", "100003", "100004", "100005", "100006", "100007", "100008", "100009", "100010", "100011", "100012", "100013", "100014", "100015", "100016", "100017", "10100", "10200", "200000", "200001", "200002", "200003", "200004", "200005", "20100", "20200", "1", "2", "3", "4", "100", "101", "102", "103", "111", "112", "114", "115", "120", "121", "123", "124", "199", "10000", "10002", "10003", "10100", "10102"]

Jul.13,2022

reference

def foo(ls):
    assert ls and ls[0] != ''
    ls2 = list(ls)
    for i in range(len(ls2)):
        if ls2[i] == '':
            ls2[i] = str(int(ls2[i-1]) + 1)
    return ls2

there is a zero filling operation missing upstairs. Add

here.
def foo(lst):
    for i, _ in enumerate(lst):
        if not _:
            lst[i] = str(int(lst[i - 1]) + 1).zfill(len(lst[i - 1]))
    return lst

lst = ['00', '01', '', '', '100000', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '10100', '10200', '200000', '', '', '', '', '', '20100', '20200', '1', '', '', '', '100', '101', '102', '103', '111', '112', '114', '115', '120', '121', '123', '124', '199', '10000', '10002', '10003', '10100', '10102']
print foo(lst)

list(reduce(lambda a,b: a+[b] if b else a+[str(int(a[-1])+1).zfill(len(a[-1]))], [s[:1]]+s[1:]))

disadvantage is that it is not intuitive enough, 2333

Menu