-1

I have a python string a = "Name:john KES:50 code:5234", how can I go through the string (a) to get the list output b = ["john", 50, 5234], keeping the order ie.

Kaita John
  • 653
  • 3
  • 13

1 Answers1

1

You can try the following code:

a = "Name:john KES:50 code:5234"
a = a.split(" ")
ls=[]
for i in a:
    c = i.split(':')[1]
    if c.isdigit():
        c = int(c)
        ls.append(c)
    else:
        ls.append(c)
ls   
Surya Lohia.
  • 446
  • 3
  • 16