I have a Python list:
List1 = ["mohit23", "jimmy24"]
I want output as:
[23, 24]
We can try using re.search along with a list comprehension:
re.search
List1 = ["mohit23", "jimmy24"] nums = [int(re.search(r'\d+$', x).group()) for x in List1] print(nums) # [23, 24]
Copyright © 2021 Jogjafile Inc.
We can try using
re.searchalong with a list comprehension: