Question: Write a function concat_if_digits(string_list) that takes a list of zero or more strings as a parameter and returns a single string obtained by concatenating together
Write a function concat_if_digits(string_list) that takes a list of zero or more strings as a parameter and returns a single string obtained by concatenating together all the strings in 'string_list' that contain any digit characters (i.e., '0' through '9') anywhere within them.
In the example below, the strings that contain digits are '22y', 'bx30' and 'cy99z'. Concatenated together they give '22ybx30cy99z'.
Hint: the string method isdigit might prove useful.
For example:
| Test | Result |
|---|---|
strings = ['abc', '22y', 'bx30', 'x', 'nope', 'cy99z'] print(concat_if_digits(strings)) | 22ybx30cy99z |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
