<tfoot id='M1or6'></tfoot>

<legend id='M1or6'><style id='M1or6'><dir id='M1or6'><q id='M1or6'></q></dir></style></legend>
    • <bdo id='M1or6'></bdo><ul id='M1or6'></ul>

        <i id='M1or6'><tr id='M1or6'><dt id='M1or6'><q id='M1or6'><span id='M1or6'><b id='M1or6'><form id='M1or6'><ins id='M1or6'></ins><ul id='M1or6'></ul><sub id='M1or6'></sub></form><legend id='M1or6'></legend><bdo id='M1or6'><pre id='M1or6'><center id='M1or6'></center></pre></bdo></b><th id='M1or6'></th></span></q></dt></tr></i><div id='M1or6'><tfoot id='M1or6'></tfoot><dl id='M1or6'><fieldset id='M1or6'></fieldset></dl></div>

        <small id='M1or6'></small><noframes id='M1or6'>

      1. 如何每行打印一个元组的元素

        时间:2023-08-31
            <tbody id='r8AK6'></tbody>
        • <legend id='r8AK6'><style id='r8AK6'><dir id='r8AK6'><q id='r8AK6'></q></dir></style></legend>

            1. <tfoot id='r8AK6'></tfoot>
                <bdo id='r8AK6'></bdo><ul id='r8AK6'></ul>
                <i id='r8AK6'><tr id='r8AK6'><dt id='r8AK6'><q id='r8AK6'><span id='r8AK6'><b id='r8AK6'><form id='r8AK6'><ins id='r8AK6'></ins><ul id='r8AK6'></ul><sub id='r8AK6'></sub></form><legend id='r8AK6'></legend><bdo id='r8AK6'><pre id='r8AK6'><center id='r8AK6'></center></pre></bdo></b><th id='r8AK6'></th></span></q></dt></tr></i><div id='r8AK6'><tfoot id='r8AK6'></tfoot><dl id='r8AK6'><fieldset id='r8AK6'></fieldset></dl></div>

                  <small id='r8AK6'></small><noframes id='r8AK6'>

                1. 本文介绍了如何每行打印一个元组的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  以下是我的 DNA 字符串相邻问题的代码:

                  Below is my code for a DNA string neighboring question:

                  chars = "ACGT"
                  
                  def neighbors(pattern, d):
                      assert(d <= len(pattern))
                  
                      if d == 0:
                          return [pattern]
                  
                      r2 = neighbors(pattern[1:], d-1)
                      r = [c + r3 for r3 in r2 for c in chars if c != pattern[0]]
                  
                      if (d < len(pattern)):
                          r2 = neighbors(pattern[1:], d)
                          r += [pattern[0] + r3 for r3 in r2]
                  
                      return r
                  def neighbors2(pattern, d):
                      return ([neighbors(pattern, d2) for d2 in range(d + 1)], [])
                  
                  print (neighbors2("ACG", 1))
                  

                  输出如下:

                  ([['ACG'], ['CCG', 'GCG', 'TCG', 'AAG', 'AGG', 'ATG', 'ACA', 'ACC', 'ACT']], [])
                  

                  如何添加一些代码并将输出更改为这种模式:

                  How can I add some codes and change the output looking like this kind of pattern:

                  CCG
                  TCG
                  GCG
                  AAG
                  ATG
                  AGG
                  ACA
                  ACC
                  ACT
                  ACG
                  

                  推荐答案

                  你可以使用compiler.ast模块中的flatten函数

                  You can use flatten function from compiler.ast module

                  from compiler.ast import flatten
                  print flatten(neighbors2("ACG", 1))
                  

                  会产生

                  ['ACG', 'CCG', 'GCG', 'TCG', 'AAG', 'AGG', 'ATG', 'ACA', 'ACC', 'ACT']
                  

                  print("
                  ".join(flatten(neighbors2("ACG", 1))))
                  

                  有这样的输出:

                  ACG
                  CCG
                  GCG
                  TCG
                  AAG
                  AGG
                  ATG
                  ACA
                  ACC
                  ACT
                  

                  这篇关于如何每行打印一个元组的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何按常见项目对元组进行分组并找到每组的平均值 下一篇:从元组列表创建 Python 列表

                  相关文章

                    <bdo id='WogFx'></bdo><ul id='WogFx'></ul>

                  <tfoot id='WogFx'></tfoot>

                  1. <legend id='WogFx'><style id='WogFx'><dir id='WogFx'><q id='WogFx'></q></dir></style></legend>

                      <small id='WogFx'></small><noframes id='WogFx'>

                      <i id='WogFx'><tr id='WogFx'><dt id='WogFx'><q id='WogFx'><span id='WogFx'><b id='WogFx'><form id='WogFx'><ins id='WogFx'></ins><ul id='WogFx'></ul><sub id='WogFx'></sub></form><legend id='WogFx'></legend><bdo id='WogFx'><pre id='WogFx'><center id='WogFx'></center></pre></bdo></b><th id='WogFx'></th></span></q></dt></tr></i><div id='WogFx'><tfoot id='WogFx'></tfoot><dl id='WogFx'><fieldset id='WogFx'></fieldset></dl></div>