且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

连接两个不同列表中的字符串

更新时间:2023-02-22 12:43:29

使用您的方法,您需要在 y 上重置迭代器每次尝试在 x 中使用新值时。

With your approach, you need to reset the iterator over y each time you try a new value in x.

可能更像这样:

for i in x:
  if i in dic:
    text.append(i)
  else:
    for j in y:
      concatenated = i + j
      if concatenated in dic:
        text.append(concatenated)

y中j的 尝试 y $ c $中的所有事物c>,否则它每次都会移动,并且永远不会回头。

The for j in y tries all the things in y, otherwise it moves on each time, and never looks back.