List는 중요한 컨테이너이며 웹 개발뿐만 아니라 일상적인 프로그래밍의 거의 모든 코드에서 사용됩니다. 사용할수록 목록을 마스터해야 하는 요구 사항도 많아지므로 작업에 대한 지식이 필요합니다.
예시
# using itertools.ziplongest # import library from itertools import zip_longest # initialising listoflist test_list = [ [('11'), ('12'), ('13')], [('21'), ('22'), ('23')], [('31'), ('32'), ('33')] ] # printing intial list print ("Initial List = ", test_list) # iterate list tuples list of list into single list res_list = [item for my_list in zip_longest(*test_list) for item in my_list if item] # print final List print ("Resultant List = ", res_list) # using itertools.ziplongest + lambda + chain # import library from itertools import zip_longest, chain # initialising listoflist test_list = [ [('11'), ('12'), ('13')], [('21'), ('22'), ('23')], [('31'), ('32'), ('33')] ] # printing intial list print ("Initial List = ", test_list) # iterate list tuples list of list into single list # using lambda + chain + filter res_list = list(filter(lambda x: x, chain(*zip_longest(*test_list)))) # print final List print ("Resultant List = ", res_list) # list using list comprehension # initialising listoflist test_list = [ [('11'), ('12'), ('13')], [('21'), ('22'), ('23')], [('31'), ('32'), ('33')] ] # printing intial list print ("Initial List = ", test_list) # iterate list tuples list of list into single list # using list comprehension res_list = [item for list2 in test_list for item in list2] # print final List print ("Resultant List = ", res_list)