Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime as dt
- from typing import List
- def split_int_string(digits: str, *at: int) -> List[int]:
- """
- Split a string at given indices and parse the parts to int.
- """
- # Make a canonical representation.
- split: List[int] = sorted(at)
- if not split or split[0] != 0:
- split.insert(0, 0)
- if split[-1] != len(digits):
- split.append(len(digits))
- return [int(digits[split[i - 1] : split[i]]) for i in range(1, len(split))]
- date = "20210421"
- time = "235930"
- print(
- f"date '{date}' and time '{time}' gives:",
- dt.datetime(*split_int_string(date, 4, 6, 8), *split_int_string(time, 2, 4)),
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement