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"]