yr3=[1950,1954,1955,1956,1959]
yr2=[1950,1951,1952,1956,1959]
yr1=[1951,1953,1957,1956,1960]
#Create a new dictionary
Year_Event_dict = dict()
yrs=[yr3,yr2,yr1]
events=['yr3','yr2','yr1']
for i in range(len(yrs) ):
for year in yrs[i] :
if year not in Year_Event_dict.keys() :
Year_Event_dict[year]=[events[i]]
else :
Year_Event_dict[year]+=[events[i]]
Year_Event_dict = sorted (Year_Event_dict.items() )
for year,events in Year_Event_dict :
if len(events) > 1 :
# not to print out the year when there was no or only one event happened.
print ("in year %d, there were %d events happened, including %s" %(year,len(events), events) )
在我看来,我会首先创建一本新词典,并使用年份作为“键”。 例如
{1950:'yr3','yr2' , 1951:'yr1', ...}
如以下代码所示:
它表明在某一年,事件的数量以及发生的事件类型。 你可以用这些信息来制作图表或其他东西。 希望这能对你有所帮助
相关问题 更多 >
编程相关推荐