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

8th Aug 2023, 10:42 AM
Thile Dorje Lama
Thile Dorje Lama - avatar
10 Réponses
+ 5
Where is your attempt for the home task?
8th Aug 2023, 11:26 AM
JaScript
JaScript - avatar
+ 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.
8th Aug 2023, 12:00 PM
JaScript
JaScript - avatar
+ 4
Okay I see. Did you get that? Where do you have a problem?
8th Aug 2023, 11:44 AM
JaScript
JaScript - avatar
8th Aug 2023, 11:31 AM
Thile Dorje Lama
Thile Dorje Lama - avatar
+ 1
It tried whole a week
8th Aug 2023, 12:06 PM
Thile Dorje Lama
Thile Dorje Lama - avatar
+ 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
9th Aug 2023, 5:07 AM
‎ ຸ
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
8th Aug 2023, 11:37 AM
Thile Dorje Lama
Thile Dorje Lama - avatar
0
My couldn't fulfill the exact result I expected
8th Aug 2023, 11:50 AM
Thile Dorje Lama
Thile Dorje Lama - avatar
0
I mean my code
8th Aug 2023, 11:50 AM
Thile Dorje Lama
Thile Dorje Lama - avatar
0
To skip the key value.. Should be working on first number of first list ...
8th Aug 2023, 11:51 AM
Thile Dorje Lama
Thile Dorje Lama - avatar