Python Convert Interval (3d/1h/5m/10s) to Seconds

Feb 25, 2021
seconds_per_unit = {"s": 1, "m": 60, "h": 3600, "d": 86400}def interval_to_seconds(s):    return int(s[:-1]) * seconds_per_unit[s[-1]]
interval_to_seconds('1m') # 60interval_to_seconds('5m') # 300interval_to_seconds('1d') # 86400

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.