开发者

Can this Python script be improved? [closed]

开发者 https://www.devze.com 2023-03-21 19:27 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

Can this Python code be improved?

   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', 'thick', 'average']:
                                            for i in ['long', 'short', 'average']:
                                                for j in [True, False]:
                                                    for k in ['thin', 'thick', 'average']:
                                                        for l in ['thin', 'thick', 'average'开发者_StackOverflow中文版]:
                                                            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)


Yes. You can use itertools.product()

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号