we have two lists, one for months and the other for numbers of days, the last one is disordered, for exemple :
t1 = [28,31,31,30,31,30,31,31,31,30,30,31]
t2 = ['Jan','Feb','March','Avr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
and we want to associate them in order to get the following result : ['Jan', 31, 'Fev', 28, 'Mars', 31, 'Avr', 30, 'Mai', 31, 'Juin', 30, 'Juil', 31, 'Aout', 31, 'Sep', 30, 'Oct', 31, 'Nov', 30, 'Dec', 31] by using python, the first list should be ordered before using extend() function to associate the two lists, so that each month can be followed by its number of days but I'm wondering if there is any other way to do that without putting the first list in order?
CodePudding user response:
finall_list = []
for i in range(len(t2)):
finall_list.append(t2[i])
finall_list.append(t1[i])
print(finall_list)
CodePudding user response:
t1 = [28,31,31,30,31,30,31,31,31,30,30,31]
t2 = ['Jan','Feb','March','Avr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
# this is main list
mainList = [[t2,t1][x%2][x//2] for x in range(24)]