Reputation: 113
I have a python function which returns list type data which is in this format:
[15, [17, 35, 34]]
first part is number and Second sub list is Time list in H:M:S
How to format and assign it as:
a = 15
time = 17:35:34 ?
Upvotes: 2
Views: 49
Reputation: 107347
You can use datetime.time
and format function :
>>> l=[15, [17, 35, 34]]
>>> a=l[0]
>>> d = datetime.time(*l[1])
>>> '{:%H:%M:%S}'.format(d)
'17:35:34'
Other example :
>>> l=[17,2,3]
>>> d = datetime.time(*l)
>>> '{:%H:%M:%S}'.format(d)
'17:02:03'
Upvotes: 2
Reputation: 45575
data = [15, [17, 35, 34]]
a, (h, m, s) = data
time = '%02d:%02d:%02d' % (h, m, s)
Upvotes: 2