RedIcon RedIcon - 6 months ago 13
Python Question

how to split string and convert to integer

numbers = "51-52"
for st in numbers:
part = st.split("-")
print(part)


this is my code so far.

My results:['5']['1']['', '']['5']['2']

Expected:['51']['52']

Answer
numbers = "51-52"
part = [int(x) for x in numbers.split("-")]
print(part)