kpokhrel
kpokhrel

Reputation: 113

how to format list and assign them separately?

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

Answers (2)

Kasravnd
Kasravnd

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

catavaran
catavaran

Reputation: 45575

data = [15, [17, 35, 34]]
a, (h, m, s) = data
time = '%02d:%02d:%02d' % (h, m, s)

Upvotes: 2

Related Questions