• <legend id='LidjU'><style id='LidjU'><dir id='LidjU'><q id='LidjU'></q></dir></style></legend>

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

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

        在范围函数内更改步长值?

        Change step value inside range function?(在范围函数内更改步长值?)
        <legend id='aHnN7'><style id='aHnN7'><dir id='aHnN7'><q id='aHnN7'></q></dir></style></legend>

            • <small id='aHnN7'></small><noframes id='aHnN7'>

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

                  <bdo id='aHnN7'></bdo><ul id='aHnN7'></ul>
                  <tfoot id='aHnN7'></tfoot>
                    <tbody id='aHnN7'></tbody>
                • 本文介绍了在范围函数内更改步长值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  list1 = [1, 2, 3, 4]
                  

                  我正在尝试找出一种方法来更改每个打印 i 的步长值

                  i'm trying to figure out a way to change the step value for each printed i

                  我尝试过的

                  r = 0
                  for i in range(0, 10, list1[r]):
                      print i
                      r = r + 1
                  

                  推荐答案

                  我建议使用 while 循环来实现你自己的生成器.示例 -

                  I would suggest implementing a generator of your own for this using while loop. Example -

                  def varied_step_range(start,stop,stepiter):
                      step = iter(stepiter)
                      while start < stop:
                          yield start
                          start += next(step)
                  

                  那么你可以把它当成——

                  Then you can use this as -

                  for i in varied_step_range(start,stop,steplist):
                      #Do your logic.
                  

                  我们执行 step = iter(stepiter) 以便 stepiter 可以是任何类型的可迭代对象.

                  We do the step = iter(stepiter)so that stepiter can be any kind of iterable.

                  演示 -

                  >>> def varied_step_range(start,stop,stepiter):
                  ...     step = iter(stepiter)
                  ...     while start < stop:
                  ...         yield start
                  ...         start += next(step)
                  ... 
                  >>> for i in varied_step_range(0,10,[1,2,3,4]):
                  ...     print i
                  ... 
                  0
                  1
                  3
                  6
                  

                  这篇关于在范围函数内更改步长值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)

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

                          <legend id='ttc4Z'><style id='ttc4Z'><dir id='ttc4Z'><q id='ttc4Z'></q></dir></style></legend>
                        • <tfoot id='ttc4Z'></tfoot>

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

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