PracticeArrays

Convert Arcade Score Cards

EasyArraystraversalaccumulationstate tracking Time not estimated Not started

Context

An arcade challenge stores each player's result as a pair of text values: points earned and level reached. Before the results are placed on the high-score display, convert every pair into integers. Some players may have identical cards, and their original order must remain unchanged.

Problem

Write a function that receives a list of score cards. Every card has exactly two digit strings: its points total followed by its level number. Create a new numeric record for each card by converting both strings to integers. Return all converted records in the same order as the input, keeping repeated cards as repeated records. If the input list is empty, return an empty list. Do not skip, merge, sort, or otherwise alter any card.

Examples

Example 1
Input: score_cards = [["10", "1"], ["25", "3"], ["10", "1"]]
Output: [[10, 1], [25, 3], [10, 1]]
Explanation: The two distinct cards are converted to [10, 1] and [25, 3], and the repeated first card remains repeated, producing [[10, 1], [25, 3], [10, 1]]. (,, )
Example 2
Input: score_cards = [["0", "0"], ["7", "2"], ["100", "10"]]
Output: [[0, 0], [7, 2], [100, 10]]
Explanation: The three cards are converted field by field, producing [[0, 0], [7, 2], [100, 10]] in the input order. (,, )
Example 3
Input: score_cards = []
Output: []
Explanation: There are no input cards, so the function returns an empty list.

Constraints

  • 0 <= len(score_cards) <= 100
  • 2 <= len(score_cards[i]) <= 2 for every i
  • 1 <= len(score_cards[i][j]) <= 8 for every i, j
  • score_cards[i][j]: alphabet digits
  • The strings inside score_cards contain digits only.
  • Types: score_cards is str[][]; result is int[][]

Function signature

def convert_score_cards(score_cards: list[list[str]]) -> list[list[int]]
score_cards list[list[str]]
A list of two-item text records, where each item is a digit string for points or level.
returns list[list[int]]
A new list containing one two-integer record for every input card, in identical order and with identical multiplicity.

Adapted from MBPP problem task_156 (CC BY 4.0). Rewritten, extended and verified by Iksha.

Notes

  • Each record always has two fields: points first and level second.
  • The result must be newly constructed rather than reusing text records.
Approved · c028-abs_610_v114 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1