In this program, we will take a string as input and get all the digits from the string.
Steps to solve the program
- Take a string as input
- Convert the string into a list using Split() and create an empty list.
- Use For loop to iterate over every word in the string.
- If the words contain all digits add the words to the empty list.
- Use isdigit() for this purpose.
- Print the new list.
#Input string
string1 = """"Sinak’s 1112 aim is to 1773 create a new generation of people who understand 444 that an organization’s
5324 success or failure is based on 555 leadership excellence and not managerial acumen"""
List1 = string1.split(" ")
List2 = []
for val in List1:
if val.isdigit():
List2.append(val)
#Printing output
print(List2)
Output :
['1112', '1773', '444', '5324', '555']