python - 在python中将整数转换为空格分隔的列表
问题描述
我的输入为:
第一行包含两个空格分隔的整数 N 和 M。然后在下一行是矩阵 A 的 NxM 输入: 输入:
4 5
11110
11010
11000
00000
我希望输出为列表列表(整数)
输出:
[[1, 1, 1, 1, 0],
[1, 1, 0, 1, 0],
[1, 1, 0, 0, 0],
[0, 0, 0, 0, 0]]
解决方案
将输入读取为字符串。然后您可以使用此代码段获取输出
op_list = []
def to_list(number):
return [int(dig) for dig in number]
op_list.append(to_list("11110"))
op_list.append(to_list("11010"))
op_list.append(to_list("11000"))
op_list.append(to_list("00000"))
print(op_list)
推荐阅读
- perl - 连接到 DBIx::Class 数据库而不重复连接细节?
- sql - 使用数字字符串作为 SqlParameter 到带有 IN 运算符的 SQL 查询资源
- java - 什么是原始类加载器?它是如何在 Java 中使用的?
- java - Android Studio NO image is seen in Image-Layout over Grid Layout
- php - 可以在对象中动态添加特征吗?
- c++ - 如何在命名空间中正确调用此函数?C++
- amazon-web-services - CNAME 条目在使用 Amazon Certificate Manager 的 NameCheap 上不起作用
- python - PyTorch 线性回归问题
- redux - 如何在 redux“timeoutScheduler”中间件文档示例中使用取消功能?
- c# - 查看器-pdf-工具栏上的硒