Create a list of time in M:S, each value must be repeated 3 times

Question:

I need to create a list of time in M:S, but each value must be repeated 3 times.[0:00,0:00,0:00,0:01,0:01,0:01,0:02…]
Thanks in advance!

Asked By: aexxy x

||

Answers:

I’ll use strings for the times in the list because I don’t know which data type you hope to use for them. I’ll also use a 24 hour clock.
Hope this helps:

[f"{m//3}:{s//3:02d}" for m in range(24*3) for s in range(60*3)]

This will only work if you are using python 3.6 or above, because that’s when f-strings were added. If you’re using a version below 3.6, you can use .format() instead, replacing every instance of f'{x}...{y:02d}' in the code with '{}...{:02d}'.format(x, y).

Edit: Modifications of int(x/3) to x//3 and replacement of secs logic to :02d based on @MadPhysict’s recommendation.

Answered By: user17301834
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.