<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. 如何每行打印一个元组的元素

        How to print out elements of tuple one per line(如何每行打印一个元组的元素)
            <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
                  

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

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                      <bdo id='WogFx'></bdo><ul id='WogFx'></ul>

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

                            <tbody id='WogFx'></tbody>
                        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>