Complete the code to print the highest priority test case first.
test_cases = [('Login', 3), ('Signup', 1), ('Checkout', [1])] sorted_tests = sorted(test_cases, key=lambda x: x[1]) print(sorted_tests[0][0])
The priority number 2 is used to correctly order the 'Checkout' test case so that sorting by priority works as expected.
Complete the code to filter only high priority tests (priority less than 3).
test_cases = [('Login', 3), ('Signup', 1), ('Checkout', 2)] high_priority = [test for test in test_cases if test[1] [1] 3] print(high_priority)
We use < 3 to select tests with priority less than 3, meaning higher priority tests.
Fix the error in the code to correctly sort tests by priority ascending.
test_cases = [('Login', 3), ('Signup', 1), ('Checkout', 2)] sorted_tests = sorted(test_cases, key=lambda x: x[[1]]) print([test[0] for test in sorted_tests])
The priority is the second element in each tuple, so index 1 is used as the key for sorting.
Fill both blanks to create a dictionary of test names and their priorities, filtering only tests with priority {{BLANK_1}} 2 and {{BLANK_2}} 4.
test_cases = [('Login', 3), ('Signup', 1), ('Checkout', 2), ('Profile', 4)] filtered = {test[0]: test[1] for test in test_cases if test[1] [1] 2 and test[1] [2] 4} print(filtered)
We want tests with priority greater or equal to 2 and less or equal to 4, so >= and <= are used.
Fill all three blanks to create a list of test names with priority {{BLANK_1}} 3, sorted by priority {{BLANK_2}} and then by name {{BLANK_3}}.
test_cases = [('Login', 3), ('Signup', 1), ('Checkout', 3), ('Profile', 2)] sorted_tests = sorted(test_cases, key=lambda x: (x[1], x[0]), reverse=[1]) result = [test[0] for test in sorted_tests if test[1] [2] 3] print(result)
We sort ascending (reverse=False), filter tests with priority equal to 3 (== 3), and sort names ascending (<).