Issue
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!
Solution
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
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.