I am trying to combine the lists below to display a date in the format 'dd/hh:mm'.
the lists are as follows:
dd = [23, 23, 24, 24, 24, 24, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27]
hh = [21, 23, 7, 9, 16, 19, 2, 5, 12, 15, 22, 1, 8, 11, 18, 21, 2, 8, 12, 12, 13, 13, 18, 22]
mm = [18, 39, 3, 42, 52, 43, 46, 41, 42, 35, 41, 27, 37, 30, 0, 58, 57, 51, 11, 20, 18, 30, 35, 5]
So combining the lists would look something like
23/21:18, 23/23:39, 24/7:3, 24/9:42 ......
and so on. I tried using a for loop (below) for this, but each time was unsurprisingly met with
finaltimes = []
zip_object = zip(dd,hh,mm)
for list1, list2, list3 in zip_object:
finaltimes.append(list1+'/'+list2+':'+list3)
TypeError: unsupported operand type(s) for +: 'int' and 'str'
I know I can't combine int and str in this loop but am not sure how to approach this? Any help is appreciated
The following should work:
finaltimes = ['{}/{}:{}'.format(*tpl) for tpl in zip(dd, hh, m)]
Try some thing like this:
finaltimes.append(f"{list1}/{list2}:{list3}")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With