get hh mm ss as integers from string "hh-mm-ss" in python

You can use the split() function in Python to separate the hours, minutes, and seconds into individual strings. Then, you can use the int() function to convert the strings into integers.

Here's an example:

main.py
time_string = "12-34-56"
hours, minutes, seconds = map(int, time_string.split("-"))
print(hours, minutes, seconds)
115 chars
4 lines

Output:

main.py
12 34 56
9 chars
2 lines

In this example, the split() method is called on the time_string variable with - as the separator. The resulting list [ "12", "34", "56"] is then unpacked into the variables hours, minutes, and seconds. Finally, the map() function applies the int() function to each element in the list, converting the strings into integers.

gistlibby LogSnag