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

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

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

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

        <tfoot id='Knvap'></tfoot>
      1. 将函数输出附加到多个列表的 Pythonic 方法

        Pythonic way to append output of function to several lists(将函数输出附加到多个列表的 Pythonic 方法)

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

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

                <tbody id='Ct8KZ'></tbody>

              • <bdo id='Ct8KZ'></bdo><ul id='Ct8KZ'></ul>
                <tfoot id='Ct8KZ'></tfoot>

              • <legend id='Ct8KZ'><style id='Ct8KZ'><dir id='Ct8KZ'><q id='Ct8KZ'></q></dir></style></legend>
                • 本文介绍了将函数输出附加到多个列表的 Pythonic 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个问题,我还没有找到很好的解决方案.我正在寻找一种更好的方法来将函数输出附加到两个或更多列表,而不使用临时变量.示例如下:

                  I have a question that I haven't quite found a good solution to. I'm looking for a better way to append function output to two or more lists, without using temp variables. Example below:

                  def f():
                    return 5,6
                  
                  a,b = [], []
                  for i in range(10):
                    tmp_a, tmp_b = f()
                    a.append(tmp_a)
                    b.append(temp_b)
                  

                  我尝试过使用 zip(*f()) 之类的东西,但还没有找到这样的解决方案.不过,任何删除这些临时变量的方法都会非常有帮助,谢谢!

                  I've tried playing around with something like zip(*f()), but haven't quite found a solution that way. Any way to remove those temp vars would be super helpful though, thanks!

                  编辑以获取更多信息:在这种情况下,函数的输出数将始终等于要附加到的列表数.我希望摆脱临时变量的主要原因是可能有 8-10 个函数输出,并且拥有这么多临时变量会变得混乱(尽管我什至不喜欢有两个).

                  Edit for additional info: In this situation, the number of outputs from the function will always equal the number of lists that are being appended to. The main reason I'm looking to get rid of temps is for the case where there are maybe 8-10 function outputs, and having that many temp variables would get messy (though I don't really even like having two).

                  推荐答案

                  def f():
                      return 5,6
                  
                  a,b = zip(*[f() for i in range(10)])
                  # this will create two tuples of elements 5 and 6 you can change 
                  # them to list by type casting it like list(a), list(b)
                  

                  这篇关于将函数输出附加到多个列表的 Pythonic 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                • <legend id='dYu5b'><style id='dYu5b'><dir id='dYu5b'><q id='dYu5b'></q></dir></style></legend>
                • <i id='dYu5b'><tr id='dYu5b'><dt id='dYu5b'><q id='dYu5b'><span id='dYu5b'><b id='dYu5b'><form id='dYu5b'><ins id='dYu5b'></ins><ul id='dYu5b'></ul><sub id='dYu5b'></sub></form><legend id='dYu5b'></legend><bdo id='dYu5b'><pre id='dYu5b'><center id='dYu5b'></center></pre></bdo></b><th id='dYu5b'></th></span></q></dt></tr></i><div id='dYu5b'><tfoot id='dYu5b'></tfoot><dl id='dYu5b'><fieldset id='dYu5b'></fieldset></dl></div>
                • <tfoot id='dYu5b'></tfoot>
                    <bdo id='dYu5b'></bdo><ul id='dYu5b'></ul>

                        <tbody id='dYu5b'></tbody>

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