How to find even numbers in a string in Python

S

Sam Fatu

Guest
I tried to find even numbers in a string

s = "75,41,14,8,73,45,-16"
evenNumbers = []

for number in s.split(","):
if int(number) % 2 == 0 and int(number) > 0:
evenNumbers += number

evenNumbers = ','.join(evenNumbers)
print("Even Numbers : \"{}\"".format(evenNumbers))


and its output is like

Even Numbers : "1,4,8"


I want to make it like

Even Numbers : "14,8"

Continue reading...
 
Top