python - 如何将平面列表转换为嵌套列表,其中包含原始列表中的每一对?
问题描述
我怎样才能打开一个列表,例如:
og_list = [0, 4, 12, 18, 20, 23]
到嵌套列表中,例如:
new_list = [[0, 4], [4, 12], [12, 18], [18, 20], [20, 23]]
我怎样才能做到这一点?
解决方案
new_list = []
for i in range(len(og_list)-1):
new_list.append( [og_list[i],og_list[i+1]] )
推荐阅读
- sql-server - 此错误代表什么:字符串或二进制数据将被截断
- google-chrome-extension - 如何将 Chrome 扩展代码中的任何文件作为 url 访问
- matlab - 分离窗口信号和峰值检测
- authentication - 使用带有 Cookie 的 OAuth 令牌从后端重定向到前端
- javascript - Object.keys(Obj[0]).map() :[] 函数的奇怪行为
- linux - (dd command linux) 最后一个字节转到下一行
- flutter - 使用 Admob 处理多个原生广告
- sql - 如何在 SQL Server Management Studio 2019 中发送我的数据库
- javascript - 在反应中将 js 迁移到 tsx
- sql-server - 有没有办法在子查询中使用计数