I’m trying to take localtime and turn it into individual reversed binary arrays/lists.
Here is my working code:
secs = time.localtime()
year, month, day, hour, minute, second, weekday, yearday, daylight = secs
seconds_string = "{0:#b}".format(second)
seconds_string = seconds_string[2:]
seconds_list = list(seconds_string[::-1])
minutes_string = "{0:#b}".format(minute)
minutes_string = minutes_string[2:]
minutes_list = list(minutes_string[::-1])
hours_string = "{0:#b}".format(hour)
hours_string = hours_string[2:]
hours_list = list(hours_string[::-1])
I would like to make this more concise if possible, but attempts like the following aren’t working.
seconds_list = list("{0:#b}".format(second)[2::-1])
Is there a way to do this that I’m missing?
What you want is actually
The syntax is a little weird; slicing is
from:to:step. This is afromofNone, atoof 1, and a step of-1; when the step is negative,fromdefaults to the end of the string, so this means “from the end of the string backwards, up to but not including position 1”.