这个Python脚本可以改进吗?

前端之家收集整理的这篇文章主要介绍了这个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',...))
原文链接:https://www.f2er.com/python/439249.html

猜你在找的Python相关文章