I have a dictionary where jumps happen in its keys. How can I find the key in between each group where the value is minimum?
For example, I have
myDict = {
        0.98:0.001,
        1.0:0.002,
        1.02: 0.0001,
        3.52:0.01,
        3.57:0.004,
        3.98: 0.005,
        4.01: 0.02,
        6.87: 0.01,
        6.90:0.02,
        6.98:0.001,
        7.0: 0.02
}

My desired output would be 1.02, 3.57, 6.98.
The actual dictionary I'm working with has over 1000 items.

Finding keys with the minimum values in each group in a dictionary with jumps (Python)
Here is a solution, supposing the dictionary is sorted in ascending order according to key (explanations in the comments of the code):
def main():
    d = {
        0.98: 0.001, 1.0: 0.002, 1.02: 0.0001,
        3.52: 0.01, 3.57: 0.004, 3.98: 0.005, 4.01: 0.02,
        6.87: 0.01, 6.90: 0.02, 6.98: 0.001, 7.0: 0.02
    }

    all_groups = []  # list to store the groups
    minimums = []  # list to store all mins
    # initializing holders for minimum key and value
    min_k = 1000
    min_v = 0

    for k, v in d.items():
        # an if-statement just to add the first group with key inside
        if len(all_groups) == 0:
            all_groups.append([k])
            min_k = k
            min_v = d.get(k)
        else:
            # check if the difference is less or equal to 1
            if k - all_groups[-1][-1] <= 1.0:
                all_groups[-1].append(k)

                # each time we add a key to a group, we check if it is the minimum
                if d.get(k) < min_v:
                    min_k = k
                    min_v = d.get(k)
            else:
                minimums.append((min_k, min_v))

                # we append a new list with the new key inside to `all_groups`
                # in which we will store the next elements
                all_groups.append([k])
                min_k = k
                min_v = d.get(k)

    minimums.append((min_k, min_v))  # adding last minimums because for loop ends without adding them

    for i in minimums:
        print(i[0])  # 1.02, 3.57, 6.98


if __name__ == "__main__":
    main()

