1
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']

StefanTflch
  • 145
  • 2
  • 14

3 Answers3

3
numbers = "51-52"
part = [int(x) for x in numbers.split("-")]
print(part)
kushtrimh
  • 906
  • 2
  • 13
  • 32
1

because it should be just:

numbers = "51-52"
print numbers.split("-")
elabard
  • 455
  • 1
  • 5
  • 16
0

for st in numbers will iterate through each character in the string, so you end up with each character separate in the resulting set. Leave that out and simply

numbers = "51-52"
parts = numbers.split("-")
print(parts)
Matt S
  • 14,976
  • 6
  • 57
  • 76