- 1

How to separate the string into the integer within python language?

Hi guys, do you know how to separate the string into the integer while execute the code within python? Sry my english is bad Like string = "The list got 2 pcs of the bread and 1 bottle of milk." Output = [2, 1] #python#beginner

17th Feb 2021, 4:01 AM
Wan Jun Wei
Wan Jun Wei - avatar
7 Respuestas
+ 4
print([c for c in input() if c.isnumeric()])
17th Feb 2021, 6:00 AM
David Ashton
David Ashton - avatar
+ 1
import re output = map(int,re.findall(r'\d+',string))
17th Feb 2021, 4:12 AM
visph
visph - avatar
0
Hi, thank you so much, By the way, do you how to use import while we're coding
17th Feb 2021, 4:56 AM
Wan Jun Wei
Wan Jun Wei - avatar
0
Like import function, I'm kinda confused on this
17th Feb 2021, 4:57 AM
Wan Jun Wei
Wan Jun Wei - avatar
0
Ok thanks
17th Feb 2021, 4:59 AM
Wan Jun Wei
Wan Jun Wei - avatar
- 1
For c in string: If type(c)== int: Output.append(c)
17th Feb 2021, 6:20 AM
Rakesh H Maheshwari
Rakesh H Maheshwari - avatar