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

      <small id='34r7I'></small><noframes id='34r7I'>

      <tfoot id='34r7I'></tfoot>
      • <bdo id='34r7I'></bdo><ul id='34r7I'></ul>
    1. <legend id='34r7I'><style id='34r7I'><dir id='34r7I'><q id='34r7I'></q></dir></style></legend>

        列表列表,将所有字符串转换为 int,Python 3

        时间:2023-08-04

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

                <tbody id='IA73r'></tbody>
                <bdo id='IA73r'></bdo><ul id='IA73r'></ul>

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

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

                  本文介绍了列表列表,将所有字符串转换为 int,Python 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试将大列表中小列表的所有元素转换为整数,所以它应该如下所示:

                  I am trying to convert all elements of the small lists in the big list to integers, so it should look like this:

                  current list:
                  list = [['1','2','3'],['8','6','8'],['2','9','3'],['2','5','7'],['5','4','1'],['0','8','7']]
                  
                  
                  for e in list:
                      for i in e:
                          i = int(i)
                  
                  new list:
                  list = [[1,2,3],[8,6,8],[2,9,3],[2,5,7],[5,4,1],[0,8,7]]
                  

                  谁能告诉我为什么这不起作用并向我展示一种有效的方法?谢谢!

                  Could anyone tell me why doesn't this work and show me a method that does work? Thanks!

                  推荐答案

                  你可以使用嵌套列表推导:

                  You can use a nested list comprehension:

                  converted = [[int(num) for num in sub] for sub in lst]
                  

                  我也将list重命名为lst,因为list是列表类型的名称,不推荐用于变量名.

                  I also renamed list to lst, because list is the name of the list type and not recommended to use for variable names.

                  这篇关于列表列表,将所有字符串转换为 int,Python 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Python,确定字符串是否应转换为 Int 或 Float 下一篇:使用 psycopg2 python 库并使用良好的转换类型工具构

                  相关文章

                  最新文章

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

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

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