Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 通过数组的路径组合_Python_Arrays_Python 3.x_Grid_Combinations - Fatal编程技术网

Python 通过数组的路径组合

Python 通过数组的路径组合,python,arrays,python-3.x,grid,combinations,Python,Arrays,Python 3.x,Grid,Combinations,我该如何解决这个问题:我有一个字母表,它由每个网格点标记出来 (0,0)(0,1)(0,2)(0,3) o l n c (1,0)(1,1)(1,2)(1,3) e t e a (2,0)(2,1)(2,2)(2,3) i b t a (3,0)(3,1)(3,2)(3,3) o m m f 我试图找到所有可能的组合通过网格创建3,4,5长度的线 ie: PossibleSolutions =

我该如何解决这个问题:我有一个字母表,它由每个网格点标记出来

(0,0)(0,1)(0,2)(0,3)    o   l   n   c   
(1,0)(1,1)(1,2)(1,3)    e   t   e   a   
(2,0)(2,1)(2,2)(2,3)    i   b   t   a   
(3,0)(3,1)(3,2)(3,3)    o   m   m   f   
我试图找到所有可能的组合通过网格创建3,4,5长度的线

   ie: PossibleSolutions = [[(0,0),(0,1),(0,2)],[(0,0),(1,1),(2,2)],[(0,0),(1,0),(2,0)]]
   each of these representing:[[o,l,n],[o,t,t],[o,e,i]]
所有可能的组合,但保持在网格布局内

from itertools import combinations

def PossibleWords(possible, board):
    words = []

    for i in range(len(possible)):
       words.append(board[possible[i]])

    return words

def Combinations(board):

    coord = list(board.keys())

    temp = []

    temp.append(list(combinations([
                                (0,0),(0,1),(0,2),(0,3),
                                (1,0),(1,1),(1,2),(1,3),
                                (2,0),(2,1),(2,2),(2,3),
                                (3,0),(3,1),(3,2),(3,3)
                                                        ], 3)))

   possible = temp[0]

   form = []
   temp = []
   solutions = []

   for i in range(len(possible)):
       form.append(PossibleWords(possible[i], board))

   for i in range(len(form)):
       temp.append(form[i])

   for i in range(len(temp)):
       solutions.append(''.join(temp[i]))

   return solutions






  output = ['ole', 'ole', 'one', 'one', 'oaf', 'oaf', 'let', 'lee', 'lei', 'let', 'lei', 'let', 'lab', 'lam', 'lam', 'lit', 'lam', 'lam', 'net', 'nee', 'net', 'net', 'nam', 'nam', 'nam', 'nam', 'cee', 'cab', 'cat', 'cam', 'cam', 'cam', 'cam', 'eta', 'eta', 'eat', 'eta', 'tea', 'tet', 'tea', 'tab', 'tat', 'tit', 'tom', 'tom', 'eat', 'eta', 'aim', 'aim', 'bam', 'bam', 'tom', 'tom']

我尝试了combines(),但由于我的网格位于列表中,因此它不遵循网格边界。任何指导都会很有帮助,谢谢。

您得到的输出是什么,以及“它不遵循网格边界”是什么意思?我在代码末尾添加了我的输出。我的意思是,python中的组合生成表的不同顺序,因为它是一个列表。ie:组合(表3)生成:['o','l','n'],['o','l','c']…];它会忽略网格的顺序,并且不会生成与网格无关的字母组合。这是否回答了您的问题?那也是我的;不,还没有。我的问题没有意义吗?人们通常不赞成发表完全相同的问题(尽管是经过编辑的问题)。我怀疑你只是在编辑上一篇文章时遇到了麻烦。要做到这一点,只需单击标签正下方的编辑链接。