-3

I'm very new to Python. I want to use python to convert a string to and integer and return only a portion of the string. I have the following string C000004N_37. I want to convert and return just the 37 of the string.

Gus
  • 1
  • 1

1 Answers1

1

Will this work for you:

def get_route_marker(user_string):
    return int(user_string.split('_')[-1])

If all of your strings are in a list called 'list_of_strings':

route_markers = [get_route_marker(user_string) for user_string in list_of_strings]
J. Corson
  • 438
  • 3
  • 7
  • It will work for that individual corridor's records.. But I have several hundred corridors. I was trying to figure out so it would be like int(C######N_###.split('_')[-1]) – Gus Sep 17 '15 at 20:53
  • I edited the code to work on any such formatted string. – J. Corson Sep 17 '15 at 23:47