这个Python脚本可以改进吗?

这个Python代码可以改进吗?

   def build_list(types):
        for x in types:
            for a in ['short','long','average']:
                for b in ['square','sloped','average']:
                    for c in ['small','large','average']:
                        for d in ['thin','thick','average']:
                            for e in ['high','low','average']:
                                for f in [True,False]:
                                    for g in [True,False]:
                                        for h in ['flat','average']:
                                            for i in ['long','short','average']:
                                                for j in [True,False]:
                                                    for k in ['thin','average']:
                                                        for l in ['thin','average']:
                                                            yield [x,a,b,c,d,e,f,g,h,i,j,k,l]
    facets_list = list(build_list(xrange(1,121)))
    print len(facets_list)
最佳答案
是.你可以使用itertools.product()

import itertools
facets_list = list(itertools.product(types,['short','average'],['square',['small',...))

相关文章

我最近重新拾起了计算机视觉,借助Python的opencv还有face_r...
说到Pooling,相信学习过CNN的朋友们都不会感到陌生。Poolin...
记得大一学Python的时候,有一个题目是判断一个数是否是复数...
文章目录 3 直方图Histogramplot1. 基本直方图的绘制 Basic ...
文章目录 5 小提琴图Violinplot1. 基础小提琴图绘制 Basic v...
文章目录 4 核密度图Densityplot1. 基础核密度图绘制 Basic ...