Python 我怎样才能简化;对于a中的x表示y表示b中的y表示c中的z……”;无序的?

Python 我怎样才能简化;对于a中的x表示y表示b中的y表示c中的z……”;无序的?,python,list-comprehension,cartesian-product,unordered,Python,List Comprehension,Cartesian Product,Unordered,[更新]缺少一件事,如果你真的有为x在A中为y在b中为z在c中…,也就是说,任意数量的结构,编写产品(A,b,c…)是很麻烦的。假设您有一个列表列表,如上例中的d。你能简单点吗?Python让我们用*a对列表进行解包,用**b对字典进行评估,但这只是表示法。嵌套的任意长度的循环和简化这样的怪物是超越如此,为进一步的研究。我想强调,标题中的问题是开放的,所以如果我接受一个问题,请不要被误导 试试这个 #!/usr/bin/python # # Description: I try to simpl

[更新]缺少一件事,如果你真的有
为x在A中为y在b中为z在c中…
,也就是说,任意数量的结构,编写
产品(A,b,c…)是很麻烦的。假设您有一个列表列表,如上例中的
d
。你能简单点吗?Python让我们用
*a
对列表进行
解包
,用
**b
对字典进行评估,但这只是表示法。嵌套的任意长度的循环和简化这样的怪物是超越如此,为进一步的研究。我想强调,标题中的问题是开放的,所以如果我接受一个问题,请不要被误导

试试这个

#!/usr/bin/python
#
# Description: I try to simplify the implementation of the thing below.
# Sets, such as (a,b,c), with irrelavant order are given. The goal is to
# simplify the messy "assignment", not sure of the term, below.
#
#
# QUESTION: How can you simplify it? 
#
# >>> a=['1','2','3']
# >>> b=['bc','b']
# >>> c=['#']
# >>> print([x+y+z for x in a for y in b for z in c])
# ['1bc#', '1b#', '2bc#', '2b#', '3bc#', '3b#']
#
# The same works with sets as well
# >>> a
# set(['a', 'c', 'b'])
# >>> b
# set(['1', '2'])
# >>> c
# set(['#'])
#
# >>> print([x+y+z for x in a for y in b for z in c])
# ['a1#', 'a2#', 'c1#', 'c2#', 'b1#', 'b2#']


#BROKEN TRIALS
d = [a,b,c]

# TRIAL 2: trying to simplify the "assignments", not sure of the term
# but see the change to the abve 
# print([x+y+z for x, y, z in zip([x,y,z], d)])

# TRIAL 3: simplifying TRIAL 2
# print([x+y+z for x, y, z in zip([x,y,z], [a,b,c])])
编辑:

你可以在很多事情上使用这个产品,就像你想做的一样

>>> from itertools import product
>>> a=['1','2','3']
>>> b=['bc','b']
>>> c=['#']
>>> map("".join, product(a,b,c))
['1bc#', '1b#', '2bc#', '2b#', '3bc#', '3b#']

@HH,我在我的回答中添加了这样的内容:
产品(*d)
等同于
产品(a、b、c)
>>> from itertools import product
>>> a=['1','2','3']
>>> b=['bc','b']
>>> c=['#']
>>> map("".join, product(a,b,c))
['1bc#', '1b#', '2bc#', '2b#', '3bc#', '3b#']
>>> list_of_things = [a,b,c]
>>> map("".join, product(*list_of_things))