找到两个连续出现的数字之间的最小值并重复该过程直到文件末尾

Find the minimum between two consecutive occurrence of numbers and repeat the process to the end of the file

下面有一个 0.txt 文件:

Report "Curve ABC" for bread and milk on New Mexico City:

Bread and mil price by markets:

milk on market "Onlyfoods"
10
bread on market "Onlyfoods"
23
milk on market "spassus"
30
bread on market "spassus"
4
bread on market "chaim"
56
milk on market "chaim"
96
bread on market "house green"
7
milk on market "house green"
0.8

我想比较第一行有任意数字的行和连续第二行也有数字的行,然后确定它们之间的最小值并打印最小值为的行号.我想对某个数字的第三次和第四次重复相同的过程,即比较它们并获得它们之间的最小值,依此类推。

例如:需要比较10和23,最小为10,行号为6;通过继续,在 20 和 4 之间,最小值为 4,行号为 12。

输出文件应该是这样的:

minimun is between 10 and 23 is 10 in line 6

minimun is between 30 and 4 is 4 in line 12
.
.
...

我提出了一个类似的问题,但得到了很多反对票,我不明白为什么这个问题没有用,因为没有人向我展示已经在 Whosebug 中发布的其他问题。

我可以结合这个问题,“calculate the difference between number lines file", with this question, ,但我一直无法理解如何做到这一点。

编辑更新 1:

替代部分伪代码:

使用 UNIX/REGEX/AWK 的起点:基本上我应该: 1 - 提取每个数值实例的行号并垂直保存到列表中的 1.txt 文件; 2 - 提取每个实例的数值并保存在 2.txt 中的垂直列表中,然后应用给定的解决方案 here 以找到每对连续行之间的最小值并保存最小值(按顺序已提取)在文件 3.txt 中; 3 - 所以我应该使用逗号或 : 等分隔符在每个 1.txt 行的左侧或右侧附加或粘贴 3.txt 的每一行,并保存在 4.txt 文件.

读取文件,创建一个空变量,检查字符串是否为数字,比较并找到最小值。

file = open("0.txt")
m = None
results = []
indexes = []

for i,d in enumerate(file):
    try:
        results.append(float(d))
        indexes.append(i+1)
    except ValueError:
        pass

for r in range(1,len(results),2):
    
    if results[r - 1] < results[r]:
         print("minimum between",results[r-1],"and",results[r],"is",results[r-1],"line",indexes[r])

    else:
        print("minimum between",results[r-1],"and",results[r],"is",results[r],"line",indexes[r])