0
I would want it skip the key value with repeated first number of the first list in the next and second is greater
output_dict = { # key 10 and value skipped 11: [[1, 22], [13, 4], [22, 52]], 12: [[2, 56], [13, 9], [23, 56]], 13: [[3, 54], [13, 13], [24, 0]], # key 14 and value skipped 15: [[4, 42], [13, 22], [26, 7]], 16: [[6, 40], [13, 26], [0, 9]], 17: [[0, 18], [14, 26], [2, 9]], 18: [[1, 16], [14, 26], [2, 9]], 19: [[2, 45], [14, 26], [2, 9]] }
10 Respuestas
+ 5
Where is your attempt for the home task?
+ 5
It's similar for me. Until a code works properly, you have to examine in testing where the algorithm should be touched up. And try again and again until it works properly.
Sometime after that, when you have learned something new and you that want, you can optimize the code. This is what the process looks like.
+ 4
Okay I see. Did you get that?
Where do you have a problem?
+ 1
It tried whole a week
+ 1
input_dict = {
10: [[1, 22], [13, 4], [22, 52]],
11: [[1, 22], [13, 9], [23, 56]],
12: [[3, 54], [13, 13], [24, 0]],
14: [[4, 42], [13, 22], [26, 7]],
15: [[6, 40], [13, 26], [0, 9]],
16: [[0, 18], [14, 26], [2, 9]],
17: [[1, 16], [14, 26], [2, 9]],
18: [[2, 45], [14, 26], [2, 9]]
}
output_dict = {}
prev_key = None
prev_value = None
for key, values in input_dict.items():
new_values = []
for value in values:
if prev_value is None or value[0] != prev_value[0] or value[1] <= prev_value[1]:
new_values.append(value)
else:
print(f"Skipped key: {key}, value: {value}")
if new_values:
output_dict[key] = new_values
prev_key = key
prev_value = new_values[-1]
print(output_dict)
Hope this helps
0
First number should be repeated in the next key and second number should be greater than repeated first number then skip the key value
0
My couldn't fulfill the exact result I expected
0
I mean my code
0
To skip the key value..
Should be working on first number of first list ...