Ask Your Question
0

Need a Function in Python to remove entries less than 2 digits from an Array

asked 2023-04-05 09:23:29 +0000

qstack gravatar image

updated 2023-04-05 10:29:19 +0000

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-04-05 09:24:28 +0000

qstack gravatar image

updated 2023-04-07 18:31:37 +0000

def remove_less_than_two_digits(arr):
    return [num for num in arr if len(str(num)) >= 2]

Here, the function takes an array arr as input and returns a new list that only contains elements with two or more digits. It does this by iterating through each element in the input array, converting it to a string using str(num), and then checking if its length is greater than or equal to 2 using len(str(num)) >= 2. If the element meets this criteria, it is added to the new list using a list comprehension.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

1 follower

Stats

Asked: 2023-04-05 09:23:29 +0000

Seen: 14 times

Last updated: Apr 07 '23