Menu

Sign in to track your progress and unlock all features.

Theme style

Log in
01. Square a number using lambdaE02. Convert a list of strings to integers with mapE03. Filter out falsy values from a listE

Problem No 2

Convert a list of strings to integers with map

Easy

8 minute session

Summary

Convert a list of numeric strings into integers using the map function.

Problem statement

Write a function strings_to_ints(lst) that takes a list of strings, where each string represents an integer (possibly with leading/trailing whitespace or a sign), and returns a new list of integers corresponding to those string values. Implement the conversion using map (or an equivalent functional approach). You may assume each string is a valid integer representation.

Task

Use map to transform each string element in a list to an integer, handling common numeric string formats.

Examples

Convert basic numeric strings

Input

strings_to_ints(['1', '20', '-3'])

Output

[1, 20, -3]

Explanation

Each string is converted to the corresponding integer.

Input format

A list of strings, e.g. ['1', ' -2', '03'].

Output format

A list of integers, e.g. [1, -2, 3].

Constraints

All list elements are valid integer strings (may include whitespace and sign). Use map for the conversion. The input list length will be between 0 and 1000.

Samples

Sample input 0

strings_to_ints([' 7', '0', '-10'])

Sample output 0

[7, 0, -10]

Explanation 0

Whitespace and sign are handled by int() during conversion.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

03:45 PM

Free preview includes 1 Teach Theory response and 1 AI hint on each of the first 3 lessons in this module.