Tech > Coding Challenges > HackerRank > Prepare > Python > Set > Set Mutations

Problem Link to the original HackerRank problem We have seen the applications of union, intersection, difference and symmetric difference operations, but these operations do not make any changes or mutations to the set. We can use the following operations to create mutations to a set: .update() or |= Update the set by adding elements from an iterable/another set. >>> H = set("Hacker") >>> R = set("Rank") >>> H.update(R) >>> print H set(['a', 'c', 'e', 'H', 'k', 'n', 'r', 'R']) .intersection_update() or &= ...

January 27, 2024 · 4 min · 666 words

Tech > Coding Challenges > HackerRank > Prepare > Python > Basic Data Types > Finding the Percentage

Problem Link to the original HackerRank problem The provided code stub will read in a dictionary containing key/value pairs of name:[marks] for a list of students. Print the average of the marks array for the student name provided, showing 2 places after the decimal. Example marks key:value pairs are 'alpha': [20, 30, 40] 'beta': [30, 50, 70] query_name = 'beta' The query_name is ‘beta’. Beta’s average score is (30 + 50 + 70) /3 = 50.0. ...

January 26, 2024 · 2 min · 285 words

Tech > Coding Challenges > HackerRank > Prepare > Python > Basic Data Types > Nested Lists

Problem Link to the original HackerRank problem Given the names and grades for each student in a class of N students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade. Note: If there are mutliple students with the second lowest grade, order their names aphabetically and print each name on a new line. Example records = [["chi", 20.0], ["beta", 50.0], ["alpha", 50.0]] ...

January 22, 2024 · 4 min · 671 words